fix windows build

This commit is contained in:
2026-03-04 21:39:39 +01:00
parent 08352dd997
commit 49e5ed6906
2 changed files with 38 additions and 34 deletions

View File

@ -10,9 +10,12 @@
#include "user_interface.hpp" #include "user_interface.hpp"
#include <filesystem> #include <filesystem>
#include <boost/program_options.hpp>
#ifndef WIN32
#include <boost/program_options.hpp>
namespace po = boost::program_options; namespace po = boost::program_options;
#endif
// TODO: Implement state discovery/enumeration // TODO: Implement state discovery/enumeration
// - Find all possible initial board states (single one for each possible statespace). // - Find all possible initial board states (single one for each possible statespace).
@ -228,6 +231,7 @@ enum class runmode
auto argparse(const int argc, char* argv[]) -> runmode auto argparse(const int argc, char* argv[]) -> runmode
{ {
#ifndef WIN32
po::options_description desc("Allowed options"); po::options_description desc("Allowed options");
desc.add_options() // desc.add_options() //
("help", "produce help message") // ("help", "produce help message") //
@ -304,6 +308,7 @@ auto argparse(const int argc, char* argv[]) -> runmode
if (vm.contains("presets")) { if (vm.contains("presets")) {
preset_file = vm["presets"].as<std::string>(); preset_file = vm["presets"].as<std::string>();
} }
#endif
return runmode::USER_INTERFACE; return runmode::USER_INTERFACE;
} }

View File

@ -16,7 +16,7 @@ auto mass_spring_system::calculate_spring_force(const size_t s) -> void
const Vector3 delta_vel = a_vel - b_vel; const Vector3 delta_vel = a_vel - b_vel;
const float sq_len = Vector3DotProduct(delta_pos, delta_pos); const float sq_len = Vector3DotProduct(delta_pos, delta_pos);
const float inv_len = rsqrt(sq_len); const float inv_len = 1.0f / sqrt(sq_len);
const float len = sq_len * inv_len; const float len = sq_len * inv_len;
const float hooke = SPRING_CONSTANT * (len - REST_LENGTH); const float hooke = SPRING_CONSTANT * (len - REST_LENGTH);
@ -86,15 +86,15 @@ auto mass_spring_system::add_spring(size_t a, size_t b) -> void
const Vector3& mass_a = positions[a]; const Vector3& mass_a = positions[a];
const Vector3& mass_b = positions[b]; const Vector3& mass_b = positions[b];
Vector3 offset{ Vector3 offset{static_cast<float>(GetRandomValue(-100, 100)),
static_cast<float>(GetRandomValue(-100, 100)), static_cast<float>(GetRandomValue(-100, 100)), static_cast<float>(GetRandomValue(-100, 100)),
static_cast<float>(GetRandomValue(-100, 100)) static_cast<float>(GetRandomValue(-100, 100))};
};
offset = Vector3Normalize(offset) * REST_LENGTH; offset = Vector3Normalize(offset) * REST_LENGTH;
// If the offset moves the mass closer to the current center of mass, flip it // If the offset moves the mass closer to the current center of mass, flip it
if (!tree.nodes.empty()) { if (!tree.nodes.empty()) {
const Vector3 mass_center_direction = Vector3Subtract(positions[a], tree.nodes[0].mass_center); const Vector3 mass_center_direction =
Vector3Subtract(positions[a], tree.nodes[0].mass_center);
const float mass_center_distance = Vector3Length(mass_center_direction); const float mass_center_distance = Vector3Length(mass_center_direction);
if (mass_center_distance > 0 && Vector3DotProduct(offset, mass_center_direction) < 0.0f) { if (mass_center_distance > 0 && Vector3DotProduct(offset, mass_center_direction) < 0.0f) {
@ -121,19 +121,19 @@ auto mass_spring_system::clear_forces() -> void
memset(forces.data(), 0, forces.size() * sizeof(Vector3)); memset(forces.data(), 0, forces.size() * sizeof(Vector3));
} }
auto mass_spring_system::calculate_spring_forces(const std::optional<BS::thread_pool<>* const> thread_pool) -> void auto mass_spring_system::calculate_spring_forces(
const std::optional<BS::thread_pool<>* const> thread_pool) -> void
{ {
#ifdef TRACY #ifdef TRACY
ZoneScoped; ZoneScoped;
#endif #endif
const auto solve_spring_force = [&](const int i) const auto solve_spring_force = [&](const int i) { calculate_spring_force(i); };
{
calculate_spring_force(i);
};
if (thread_pool) { if (thread_pool) {
(*thread_pool)->submit_loop(0, springs.size(), solve_spring_force, SMALL_TASK_BLOCK_SIZE).wait(); (*thread_pool)
->submit_loop(0, springs.size(), solve_spring_force, SMALL_TASK_BLOCK_SIZE)
.wait();
} else { } else {
for (size_t i = 0; i < springs.size(); ++i) { for (size_t i = 0; i < springs.size(); ++i) {
solve_spring_force(i); solve_spring_force(i);
@ -141,7 +141,8 @@ auto mass_spring_system::calculate_spring_forces(const std::optional<BS::thread_
} }
} }
auto mass_spring_system::calculate_repulsion_forces(const std::optional<BS::thread_pool<>* const> thread_pool) -> void auto mass_spring_system::calculate_repulsion_forces(
const std::optional<BS::thread_pool<>* const> thread_pool) -> void
{ {
#ifdef TRACY #ifdef TRACY
ZoneScoped; ZoneScoped;
@ -155,7 +156,9 @@ auto mass_spring_system::calculate_repulsion_forces(const std::optional<BS::thre
// Calculate forces using Barnes-Hut // Calculate forces using Barnes-Hut
if (thread_pool) { if (thread_pool) {
(*thread_pool)->submit_loop(0, positions.size(), solve_octree, LARGE_TASK_BLOCK_SIZE).wait(); (*thread_pool)
->submit_loop(0, positions.size(), solve_octree, LARGE_TASK_BLOCK_SIZE)
.wait();
} else { } else {
for (size_t i = 0; i < positions.size(); ++i) { for (size_t i = 0; i < positions.size(); ++i) {
solve_octree(i); solve_octree(i);
@ -163,16 +166,14 @@ auto mass_spring_system::calculate_repulsion_forces(const std::optional<BS::thre
} }
} }
auto mass_spring_system::update(const float dt, const std::optional<BS::thread_pool<>* const> thread_pool) -> void auto mass_spring_system::update(const float dt,
const std::optional<BS::thread_pool<>* const> thread_pool) -> void
{ {
#ifdef TRACY #ifdef TRACY
ZoneScoped; ZoneScoped;
#endif #endif
const auto update = [&](const int i) const auto update = [&](const int i) { verlet_update(i, dt); };
{
verlet_update(i, dt);
};
if (thread_pool) { if (thread_pool) {
(*thread_pool)->submit_loop(0, positions.size(), update, SMALL_TASK_BLOCK_SIZE).wait(); (*thread_pool)->submit_loop(0, positions.size(), update, SMALL_TASK_BLOCK_SIZE).wait();
@ -183,7 +184,8 @@ auto mass_spring_system::update(const float dt, const std::optional<BS::thread_p
} }
} }
auto mass_spring_system::center_masses(const std::optional<BS::thread_pool<>* const> thread_pool) -> void auto mass_spring_system::center_masses(const std::optional<BS::thread_pool<>* const> thread_pool)
-> void
{ {
Vector3 mean = Vector3Zero(); Vector3 mean = Vector3Zero();
for (const Vector3& pos : positions) { for (const Vector3& pos : positions) {
@ -191,10 +193,7 @@ auto mass_spring_system::center_masses(const std::optional<BS::thread_pool<>* co
} }
mean /= static_cast<float>(positions.size()); mean /= static_cast<float>(positions.size());
const auto center_mass = [&](const int i) const auto center_mass = [&](const int i) { positions[i] -= mean; };
{
positions[i] -= mean;
};
if (thread_pool) { if (thread_pool) {
(*thread_pool)->submit_loop(0, positions.size(), center_mass, SMALL_TASK_BLOCK_SIZE).wait(); (*thread_pool)->submit_loop(0, positions.size(), center_mass, SMALL_TASK_BLOCK_SIZE).wait();