diff options
| author | Travis Curtsinger <93950613+tcurtsinger@users.noreply.github.com> | 2026-11-23 15:56:54 -0600 |
|---|---|---|
| committer | Travis Curtsinger <93950613+tcurtsinger@users.noreply.github.com> | 2026-11-23 15:56:54 -0600 |
| commit | 72e90d8ce515a22ee84ed99f669ae5d145b7a1b3 (patch) | |
| tree | 95d934c77e0b2000534b532a24fa2048f565f13f /runtime/test/vk_sandbox.cpp | |
| parent | 5d74c272363f2703265d44e6aaab1a1df8ddfaf3 (diff) | |
Build the sandbox ground grid on first walk or drive
Diffstat (limited to 'runtime/test/vk_sandbox.cpp')
| -rw-r--r-- | runtime/test/vk_sandbox.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/runtime/test/vk_sandbox.cpp b/runtime/test/vk_sandbox.cpp index b5de7bd13..554e6f647 100644 --- a/runtime/test/vk_sandbox.cpp +++ b/runtime/test/vk_sandbox.cpp | |||
| @@ -33,6 +33,7 @@ | |||
| 33 | #include <cstdlib> | 33 | #include <cstdlib> |
| 34 | #include <cstring> | 34 | #include <cstring> |
| 35 | #include <fstream> | 35 | #include <fstream> |
| 36 | #include <optional> | ||
| 36 | #include <string> | 37 | #include <string> |
| 37 | #include <unordered_map> | 38 | #include <unordered_map> |
| 38 | #include <vector> | 39 | #include <vector> |
| @@ -144,7 +145,7 @@ struct Ground { | |||
| 144 | float cell = 4, x0 = 0, y0 = 0; | 145 | float cell = 4, x0 = 0, y0 = 0; |
| 145 | int nx = 0, ny = 0; | 146 | int nx = 0, ny = 0; |
| 146 | std::vector<std::vector<float>> tris; // per cell: 9 floats a triangle | 147 | std::vector<std::vector<float>> tris; // per cell: 9 floats a triangle |
| 147 | void build(const Scene& s) { | 148 | explicit Ground(const Scene& s) { |
| 148 | float lo[2] = {1e30f, 1e30f}, hi[2] = {-1e30f, -1e30f}; | 149 | float lo[2] = {1e30f, 1e30f}, hi[2] = {-1e30f, -1e30f}; |
| 149 | std::vector<float> all; | 150 | std::vector<float> all; |
| 150 | for (const Draw& d : s.draws) { | 151 | for (const Draw& d : s.draws) { |
| @@ -639,7 +640,7 @@ int main(int argc, char** argv) { | |||
| 639 | if (make_swap() < 0) { std::fprintf(stderr, "cannot create a swapchain (TRANSFER_DST unsupported?)\n"); return 1; } | 640 | if (make_swap() < 0) { std::fprintf(stderr, "cannot create a swapchain (TRANSFER_DST unsupported?)\n"); return 1; } |
| 640 | VkSemaphoreCreateInfo semi{VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO}; | 641 | VkSemaphoreCreateInfo semi{VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO}; |
| 641 | VkSemaphore acquired; CHECK(vkCreateSemaphore(dev, &semi, nullptr, &acquired)); | 642 | VkSemaphore acquired; CHECK(vkCreateSemaphore(dev, &semi, nullptr, &acquired)); |
| 642 | Ground ground; ground.build(scene); | 643 | std::optional<Ground> ground; |
| 643 | auto last = std::chrono::steady_clock::now(); | 644 | auto last = std::chrono::steady_clock::now(); |
| 644 | bool shot_held = false; | 645 | bool shot_held = false; |
| 645 | int frame = 0; | 646 | int frame = 0; |
| @@ -662,6 +663,10 @@ int main(int argc, char** argv) { | |||
| 662 | cam.pos[0] += r[0] * side * v; cam.pos[1] += r[1] * side * v; | 663 | cam.pos[0] += r[0] * side * v; cam.pos[1] += r[1] * side * v; |
| 663 | cam.pos[2] += (float(key('E')) - float(key('Q'))) * v; | 664 | cam.pos[2] += (float(key('E')) - float(key('Q'))) * v; |
| 664 | } else { | 665 | } else { |
| 666 | if (!ground) { | ||
| 667 | ground.emplace(scene); | ||
| 668 | last = std::chrono::steady_clock::now(); // Exclude grid construction from the next movement step. | ||
| 669 | } | ||
| 665 | const float h = std::hypot(f[0], f[1]) > 1e-4f ? std::hypot(f[0], f[1]) : 1; | 670 | const float h = std::hypot(f[0], f[1]) > 1e-4f ? std::hypot(f[0], f[1]) : 1; |
| 666 | if (cam.mode == 1) cam.speed = fwd * (key(VK_SHIFT) ? 7.f : 2.5f); | 671 | if (cam.mode == 1) cam.speed = fwd * (key(VK_SHIFT) ? 7.f : 2.5f); |
| 667 | else { cam.speed += fwd * 12.f * dt; cam.speed *= std::pow(0.6f, dt); cam.yaw -= side * dt * std::clamp(cam.speed / 10.f, -1.f, 1.f); } | 672 | else { cam.speed += fwd * 12.f * dt; cam.speed *= std::pow(0.6f, dt); cam.yaw -= side * dt * std::clamp(cam.speed / 10.f, -1.f, 1.f); } |
| @@ -669,7 +674,7 @@ int main(int argc, char** argv) { | |||
| 669 | if (cam.mode == 1) { cam.pos[0] += r[0] * side * 2.5f * dt; cam.pos[1] += r[1] * side * 2.5f * dt; } | 674 | if (cam.mode == 1) { cam.pos[0] += r[0] * side * 2.5f * dt; cam.pos[1] += r[1] * side * 2.5f * dt; } |
| 670 | const float eye = cam.mode == 1 ? 1.7f : 1.2f; | 675 | const float eye = cam.mode == 1 ? 1.7f : 1.2f; |
| 671 | float gz; | 676 | float gz; |
| 672 | if (ground.height(cam.pos[0], cam.pos[1], cam.pos[2] - eye + 0.6f, gz)) cam.pos[2] = gz + eye; | 677 | if (ground->height(cam.pos[0], cam.pos[1], cam.pos[2] - eye + 0.6f, gz)) cam.pos[2] = gz + eye; |
| 673 | } | 678 | } |
| 674 | uint32_t idx = 0; | 679 | uint32_t idx = 0; |
| 675 | if (!swap) { // minimised at start or since the last resize | 680 | if (!swap) { // minimised at start or since the last resize |