make windows-compliant

- fix BS_thread_pool include error (pulls in windows.h, symbols were
redefined)
- remove all std::println uses :(, seems like mingw doesn't like those
- allow to disable backward from cmake
This commit is contained in:
2026-02-27 12:31:08 +01:00
parent 16df3b7d51
commit 85ed3a758a
11 changed files with 110 additions and 60 deletions

View File

@ -16,7 +16,6 @@ message("-- CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}")
message("-- CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}")
find_package(raylib REQUIRED)
find_package(Backward REQUIRED)
# Headers + Sources
include_directories(include)
@ -38,10 +37,16 @@ set(SOURCES
# Main target
add_executable(masssprings ${SOURCES})
target_include_directories(masssprings PUBLIC ${RAYLIB_CPP_INCLUDE_DIR})
if(NOT DEFINED DISABLE_BACKWARD)
find_package(Backward REQUIRED)
target_link_libraries(masssprings PUBLIC raylib Backward::Backward)
target_compile_definitions(masssprings PUBLIC BACKWARD)
else()
target_link_libraries(masssprings PUBLIC raylib)
endif()
# Tracy target
if(USE_TRACY)
if(NOT DEFINED DISABLE_TRACY)
include(FetchContent)
FetchContent_Declare(tracy
GIT_REPOSITORY https://github.com/wolfpld/tracy.git
@ -56,10 +61,16 @@ if(USE_TRACY)
add_executable(masssprings_tracy ${SOURCES})
target_include_directories(masssprings_tracy PUBLIC ${RAYLIB_CPP_INCLUDE_DIR})
target_compile_definitions(masssprings_tracy PRIVATE TRACY)
if(NOT DEFINED DISABLE_BACKWARD)
target_link_libraries(masssprings_tracy PUBLIC raylib Backward::Backward TracyClient)
target_compile_definitions(masssprings_tracy PUBLIC BACKWARD)
else()
target_link_libraries(masssprings_tracy PUBLIC raylib TracyClient)
endif()
endif()
# LTO
if (NOT WIN32)
include(CheckIPOSupported)
check_ipo_supported(RESULT supported OUTPUT error)
if(supported)
@ -71,3 +82,4 @@ if(supported)
else()
message(STATUS "IPO / LTO not supported: <${error}>")
endif()
endif()

View File

@ -1 +1 @@
./cmake-build-debug/compile_commands.json
./cmake-build-release/compile_commands.json

View File

@ -4,9 +4,9 @@
#include <raylib.h>
#define THREADPOOL // Enable physics threadpool
#define BACKWARD // Enable pretty stack traces
// Gets set by CMake
// #define BACKWARD // Enable pretty stack traces
// #define TRACY // Enable tracy profiling support
// Window

View File

@ -8,7 +8,6 @@
#include <condition_variable>
#include <cstddef>
#include <mutex>
#include <print>
#include <queue>
#include <raylib.h>
#include <raymath.h>
@ -17,8 +16,16 @@
#include <vector>
#ifdef THREADPOOL
#if defined(_WIN32)
#define NOGDI // All GDI defines and routines
#define NOUSER // All USER defines and routines
#endif
#define BS_THREAD_POOL_NATIVE_EXTENSIONS
#include <BS_thread_pool.hpp>
#if defined(_WIN32) // raylib uses these names as function parameters
#undef near
#undef far
#endif
#endif
#ifdef TRACY
@ -78,10 +85,16 @@ public:
: threads(std::thread::hardware_concurrency() - 1, SetThreadName)
#endif
{
std::println("Using Barnes-Hut + Octree repulsion force calculation.");
std::cout << std::format(
"Using Barnes-Hut + Octree repulsion force calculation.")
<< std::endl;
#ifdef THREADPOOL
std::println("Thread-pool: {} threads.", threads.get_thread_count());
std::cout << std::format("Thread-pool: {} threads.",
threads.get_thread_count())
<< std::endl;
#else
std::cout << std::format("Thread-pool: Disabled.") << std::endl;
#endif
};

View File

@ -7,7 +7,7 @@
#include <cstddef>
#include <format>
#include <functional>
#include <print>
#include <iostream>
#include <string>
#include <vector>
@ -40,7 +40,7 @@ public:
: x(_x), y(_y), width(_width), height(_height), target(_target),
immovable(_immovable) {
if (_x < 0 || _x + _width >= 10 || _y < 0 || _y + _height >= 10) {
std::println("Block must fit in a 9x9 board!");
std::cout << std::format("Block must fit in a 9x9 board!") << std::endl;
exit(1);
}
}
@ -92,11 +92,12 @@ public:
}
if (_x < 0 || _x + width >= 10 || _y < 0 || _y + height >= 10) {
std::println("Block must fit in a 9x9 board!");
std::cout << std::format("Block must fit in a 9x9 board!") << std::endl;
exit(1);
}
if (block.length() != 2) {
std::println("Block representation must have length 2!");
std::cout << std::format("Block representation must have length 2!")
<< std::endl;
exit(1);
}
}
@ -186,12 +187,15 @@ public:
_height, _target_x, _target_y,
std::string(_width * _height * 2, '.'))) {
if (_width < 1 || _width > 9 || _height < 1 || _height > 9) {
std::println("State width/height must be in [1, 9]!");
std::cout << std::format("State width/height must be in [1, 9]!")
<< std::endl;
exit(1);
}
if (_target_x < 0 || _target_x >= 9 || _target_y < 0 || _target_y >= 9) {
if (_target_x != 9 && _target_y != 9) {
std::println("State target must be within the board bounds!");
std::cout << std::format(
"State target must be within the board bounds!")
<< std::endl;
exit(1);
}
}
@ -209,19 +213,23 @@ public:
target_y(std::stoi(_state.substr(4, 1))),
restricted(_state.substr(0, 1) == "R"), state(_state) {
if (width < 1 || width > 9 || height < 1 || height > 9) {
std::println("State width/height must be in [1, 9]!");
std::cout << std::format("State width/height must be in [1, 9]!")
<< std::endl;
exit(1);
}
if (target_x < 0 || target_x >= 9 || target_y < 0 || target_y >= 9) {
if (target_x != 9 && target_y != 9) {
std::println("State target must be within the board bounds!");
std::cout << std::format(
"State target must be within the board bounds!")
<< std::endl;
exit(1);
}
}
if (static_cast<int>(_state.length()) != width * height * 2 + prefix) {
std::println(
"State representation must have length width * height * 2 + {}!",
prefix);
std::cout << std::format("State representation must have length width * "
"height * 2 + {}!",
prefix)
<< std::endl;
exit(1);
}
}

View File

@ -44,7 +44,7 @@ auto Grid::Bounds() const -> Rectangle {
auto Grid::Bounds(int _x, int _y, int _width, int _height) const -> Rectangle {
if (_x < 0 || _x + _width > columns || _y < 0 || _y + _height > rows) {
std::println("Grid bounds are outside range.");
std::cout << std::format("Grid bounds are outside range.") << std::endl;
exit(1);
}
@ -71,7 +71,7 @@ auto Grid::SquareBounds(int _x, int _y, int _width, int _height) const
// filled
if (_x < 0 || _x + _width > columns || _y < 0 || _y + _height > rows) {
std::println("Grid bounds are outside range.");
std::cout << std::format("Grid bounds are outside range.") << std::endl;
exit(1);
}

View File

@ -1,8 +1,6 @@
#include "input.hpp"
#include "config.hpp"
#include <algorithm>
#include <print>
#include <raylib.h>
#ifdef TRACY
@ -269,16 +267,18 @@ auto InputHandler::MoveBlockWes() -> void {
}
auto InputHandler::PrintState() const -> void {
std::println("State: \"{}\"", state.current_state.state);
std::cout << std::format("State: \"{}\"", state.current_state.state)
<< std::endl;
Block sel = state.current_state.GetBlock(sel_x, sel_y);
int idx = state.current_state.GetIndex(sel.x, sel.y) - State::prefix;
if (sel.IsValid()) {
std::println("Sel: \"{}{}{}{}\"",
std::cout << std::format("Sel: \"{}{}{}{}\"",
state.current_state.state.substr(0, State::prefix),
std::string(idx, '.'), sel.ToString(),
std::string(state.current_state.state.length() - idx -
State::prefix - 2,
'.'));
std::string(state.current_state.state.length() -
idx - State::prefix - 2,
'.'))
<< std::endl;
}
}

View File

@ -36,6 +36,18 @@ auto main(int argc, char *argv[]) -> int {
preset_file = argv[1];
}
#ifdef BACKWARD
std::cout << std::format("Backward stack-traces enabled.") << std::endl;
#else
std::cout << std::format("Backward stack-traces disabled.") << std::endl;
#endif
#ifdef TRACY
std::cout << std::format("Tracy adapter enabled.") << std::endl;
#else
std::cout << std::format("Tracy adapter disabled.") << std::endl;
#endif
// RayLib window setup
SetTraceLogLevel(LOG_ERROR);
SetConfigFlags(FLAG_VSYNC_HINT);

View File

@ -10,11 +10,6 @@
#include <utility>
#include <vector>
#ifdef THREADPOOL
#define BS_THREAD_POOL_NATIVE_EXTENSIONS
#include <BS_thread_pool.hpp>
#endif
#ifdef TRACY
#include "tracy.hpp"
#include <tracy/Tracy.hpp>

View File

@ -1,7 +1,6 @@
#include "puzzle.hpp"
#include "config.hpp"
#include <print>
#include <unordered_set>
#ifdef TRACY
@ -389,8 +388,9 @@ auto State::Closure() const
}
} while (remaining_states.size() > 0);
std::println("State space has size {} with {} transitions.", states.size(),
links.size());
std::cout << std::format("State space has size {} with {} transitions.",
states.size(), links.size())
<< std::endl;
return std::make_pair(states, links);
}

View File

@ -4,7 +4,6 @@
#include <fstream>
#include <ios>
#include <print>
#include <raymath.h>
#ifdef TRACY
@ -17,7 +16,9 @@ auto StateManager::ParsePresetFile(const std::string &_preset_file) -> bool {
std::ifstream file(preset_file);
if (!file) {
std::println("Preset file \"{}\" couldn't be loaded.", preset_file);
std::cout << std::format("Preset file \"{}\" couldn't be loaded.",
preset_file)
<< std::endl;
return false;
}
@ -33,7 +34,9 @@ auto StateManager::ParsePresetFile(const std::string &_preset_file) -> bool {
}
if (preset_lines.size() == 0 || comment_lines.size() != preset_lines.size()) {
std::println("Preset file \"{}\" couldn't be loaded.", preset_file);
std::cout << std::format("Preset file \"{}\" couldn't be loaded.",
preset_file)
<< std::endl;
return false;
}
@ -43,24 +46,29 @@ auto StateManager::ParsePresetFile(const std::string &_preset_file) -> bool {
}
comments = comment_lines;
std::println("Loaded {} presets from \"{}\".", preset_lines.size(),
preset_file);
std::cout << std::format("Loaded {} presets from \"{}\".",
preset_lines.size(), preset_file)
<< std::endl;
return true;
}
auto StateManager::AppendPresetFile(const std::string preset_name) -> void {
std::println("Saving preset \"{}\" to \"{}\"", preset_name, preset_file);
std::cout << std::format("Saving preset \"{}\" to \"{}\"", preset_name,
preset_file)
<< std::endl;
std::ofstream file(preset_file, std::ios_base::app | std::ios_base::out);
if (!file) {
std::println("Preset file \"{}\" couldn't be loaded.", preset_file);
std::cout << std::format("Preset file \"{}\" couldn't be loaded.",
preset_file)
<< std::endl;
return;
}
file << "\n# " << preset_name << "\n" << current_state.state << std::flush;
std::println("Refreshing presets...");
std::cout << std::format("Refreshing presets...") << std::endl;
if (ParsePresetFile(preset_file)) {
LoadPreset(presets.size() - 1);
}
@ -139,7 +147,8 @@ auto StateManager::FillGraph() -> void {
// Sanity check. Both values need to be equal
// for (const auto &[mass, state] : masses) {
// std::println("Masses: {}, States: {}", mass, states.at(state));
// std::cout << std::format("Masses: {}, States: {}", mass,
// states.at(state)) << std::endl;
// }
}
@ -226,8 +235,8 @@ auto StateManager::FindTargetDistances() -> void {
target_distances = CalculateDistances(states.size(), springs, targets);
// std::println("Calculated {} distances to {} targets.",
// target_distances.distances.size(), targets.size());
// std::cout << std::format("Calculated {} distances to {} targets.",
// target_distances.distances.size(), targets.size()) << std::endl;
}
auto StateManager::FindTargetPath() -> void {
@ -236,7 +245,8 @@ auto StateManager::FindTargetPath() -> void {
}
winning_path = GetPath(target_distances, CurrentMassIndex());
// std::println("Nearest target is {} moves away.", winning_path.size());
// std::cout << std::format("Nearest target is {} moves away.",
// winning_path.size()) << std::endl;
}
auto StateManager::FindWorstState() -> State {