update compiler flags, fix tracy allocation profiling, fix compiler warnings
This commit is contained in:
@ -3,25 +3,34 @@ project(MassSprings)
|
|||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 23)
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
|
|
||||||
|
|
||||||
find_package(raylib REQUIRED)
|
find_package(raylib REQUIRED)
|
||||||
find_package(OpenMP REQUIRED)
|
|
||||||
|
|
||||||
# Need to enable/disable this based on a variable for nix build
|
# Need to enable/disable this based on a variable for nix build
|
||||||
if(USE_TRACY)
|
if(USE_TRACY)
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
FetchContent_Declare(tracy
|
FetchContent_Declare(tracy
|
||||||
GIT_REPOSITORY https://github.com/wolfpld/tracy.git
|
GIT_REPOSITORY https://github.com/wolfpld/tracy.git
|
||||||
GIT_TAG v0.11.1
|
GIT_TAG v0.11.1
|
||||||
GIT_SHALLOW TRUE
|
GIT_SHALLOW TRUE
|
||||||
GIT_PROGRESS TRUE
|
GIT_PROGRESS TRUE
|
||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(tracy)
|
FetchContent_MakeAvailable(tracy)
|
||||||
option(TRACY_ENABLE "" ON)
|
option(TRACY_ENABLE "" ON)
|
||||||
option(TRACY_ON_DEMAND "" ON)
|
option(TRACY_ON_DEMAND "" ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wcast-align -Wno-unused-parameter -Wunreachable-code")
|
||||||
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og -ggdb -fsanitize=undefined") # -fsanitize=address already fails on InitWindow()
|
||||||
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -march=native")
|
||||||
|
|
||||||
|
message("-- CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
|
||||||
|
message("-- CMAKE_C_FLAGS_DEBUG: ${CMAKE_C_FLAGS_DEBUG}")
|
||||||
|
message("-- CMAKE_C_FLAGS_RELEASE: ${CMAKE_C_FLAGS_RELEASE}")
|
||||||
|
message("-- CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
|
||||||
|
message("-- CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}")
|
||||||
|
message("-- CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}")
|
||||||
|
|
||||||
include_directories(include)
|
include_directories(include)
|
||||||
|
|
||||||
add_executable(masssprings
|
add_executable(masssprings
|
||||||
@ -33,11 +42,22 @@ add_executable(masssprings
|
|||||||
src/puzzle.cpp
|
src/puzzle.cpp
|
||||||
src/state.cpp
|
src/state.cpp
|
||||||
src/input.cpp
|
src/input.cpp
|
||||||
|
src/tracy.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(masssprings PUBLIC ${RAYLIB_CPP_INCLUDE_DIR})
|
target_include_directories(masssprings PUBLIC ${RAYLIB_CPP_INCLUDE_DIR})
|
||||||
|
|
||||||
if(USE_TRACY)
|
if(USE_TRACY)
|
||||||
target_link_libraries(masssprings PUBLIC raylib OpenMP::OpenMP_CXX TracyClient)
|
target_link_libraries(masssprings PUBLIC raylib TracyClient)
|
||||||
else()
|
else()
|
||||||
target_link_libraries(masssprings PUBLIC raylib OpenMP::OpenMP_CXX)
|
target_link_libraries(masssprings PUBLIC raylib)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include(CheckIPOSupported)
|
||||||
|
check_ipo_supported(RESULT supported OUTPUT error)
|
||||||
|
if(supported)
|
||||||
|
message(STATUS "IPO / LTO enabled")
|
||||||
|
set_property(TARGET masssprings PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||||
|
else()
|
||||||
|
message(STATUS "IPO / LTO not supported: <${error}>")
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
./cmake-build-release/compile_commands.json
|
./cmake-build-debug/compile_commands.json
|
||||||
150
flake.nix
150
flake.nix
@ -26,76 +26,76 @@ rec {
|
|||||||
# ===========================================================================================
|
# ===========================================================================================
|
||||||
|
|
||||||
# 64 bit C/C++ compilers that don't collide (use the same libc)
|
# 64 bit C/C++ compilers that don't collide (use the same libc)
|
||||||
bintools = pkgs.wrapBintoolsWith {
|
# bintools = pkgs.wrapBintoolsWith {
|
||||||
bintools = pkgs.bintools.bintools; # Unwrapped bintools
|
# bintools = pkgs.bintools.bintools; # Unwrapped bintools
|
||||||
libc = pkgs.glibc;
|
# libc = pkgs.glibc;
|
||||||
};
|
# };
|
||||||
gcc = lib.hiPrio (pkgs.wrapCCWith {
|
# gcc = lib.hiPrio (pkgs.wrapCCWith {
|
||||||
cc = pkgs.gcc.cc; # Unwrapped gcc
|
# cc = pkgs.gcc.cc; # Unwrapped gcc
|
||||||
libc = pkgs.glibc;
|
# libc = pkgs.glibc;
|
||||||
bintools = bintools;
|
# bintools = bintools;
|
||||||
});
|
# });
|
||||||
clang = pkgs.wrapCCWith {
|
# clang = pkgs.wrapCCWith {
|
||||||
cc = pkgs.clang.cc; # Unwrapped clang
|
# cc = pkgs.clang.cc; # Unwrapped clang
|
||||||
libc = pkgs.glibc;
|
# libc = pkgs.glibc;
|
||||||
bintools = bintools;
|
# bintools = bintools;
|
||||||
};
|
# };
|
||||||
|
|
||||||
# Raylib CPP wrapper
|
# Raylib CPP wrapper
|
||||||
raylib-cpp = stdenv.mkDerivation {
|
# raylib-cpp = stdenv.mkDerivation {
|
||||||
pname = "raylib-cpp";
|
# pname = "raylib-cpp";
|
||||||
version = "5.5.0-unstable-2025-11-12";
|
# version = "5.5.0-unstable-2025-11-12";
|
||||||
|
#
|
||||||
|
# src = pkgs.fetchFromGitHub {
|
||||||
|
# owner = "RobLoach";
|
||||||
|
# repo = "raylib-cpp";
|
||||||
|
# rev = "21b0d0f57a09a7f741d20b7157f440ae87f02c76";
|
||||||
|
# hash = "sha256-P9x6Zc5t648gR7oYXe38PEX/a4oh4PfuVCnjT0vC10k=";
|
||||||
|
# };
|
||||||
|
#
|
||||||
|
# # autoPatchelfHook is needed for appendRunpaths
|
||||||
|
# nativeBuildInputs = with pkgs; [
|
||||||
|
# cmake
|
||||||
|
# # autoPatchelfHook
|
||||||
|
# ];
|
||||||
|
#
|
||||||
|
# buildInputs = with pkgs; [
|
||||||
|
# raylib
|
||||||
|
# glfw
|
||||||
|
# SDL2
|
||||||
|
# ];
|
||||||
|
#
|
||||||
|
# propagatedBuildInputs = with pkgs; [
|
||||||
|
# libGLU
|
||||||
|
# libx11
|
||||||
|
# ];
|
||||||
|
#
|
||||||
|
# cmakeFlags = [
|
||||||
|
# "-DBUILD_RAYLIB_CPP_EXAMPLES=OFF"
|
||||||
|
# "-DBUILD_TESTING=OFF"
|
||||||
|
# # Point CMake to the nixpkgs raylib so it doesn't try to fetch its own
|
||||||
|
# "-Draylib_DIR=${pkgs.raylib}/lib/cmake/raylib"
|
||||||
|
# ];
|
||||||
|
# };
|
||||||
|
|
||||||
src = pkgs.fetchFromGitHub {
|
# octree = stdenv.mkDerivation {
|
||||||
owner = "RobLoach";
|
# pname = "octree";
|
||||||
repo = "raylib-cpp";
|
# version = "2.5-unstable-2025-12-18";
|
||||||
rev = "21b0d0f57a09a7f741d20b7157f440ae87f02c76";
|
#
|
||||||
hash = "sha256-P9x6Zc5t648gR7oYXe38PEX/a4oh4PfuVCnjT0vC10k=";
|
# src = pkgs.fetchFromGitHub {
|
||||||
};
|
# owner = "attcs";
|
||||||
|
# repo = "octree";
|
||||||
# autoPatchelfHook is needed for appendRunpaths
|
# rev = "5058b3090c8b88e405fe2bfddd6c1c872f2b79d2";
|
||||||
nativeBuildInputs = with pkgs; [
|
# hash = "sha256-a/aDGQ7cj1GbCjts2s9VEaxyFnL6PF+xJOsSxm9o+4M=";
|
||||||
cmake
|
# };
|
||||||
# autoPatchelfHook
|
#
|
||||||
];
|
# # Header-only library
|
||||||
|
# dontBuild = true;
|
||||||
buildInputs = with pkgs; [
|
# installPhase = ''
|
||||||
raylib
|
# mkdir -p $out/include
|
||||||
glfw
|
# mv ./*.h $out/include/
|
||||||
SDL2
|
# '';
|
||||||
];
|
# };
|
||||||
|
|
||||||
propagatedBuildInputs = with pkgs; [
|
|
||||||
libGLU
|
|
||||||
libx11
|
|
||||||
];
|
|
||||||
|
|
||||||
cmakeFlags = [
|
|
||||||
"-DBUILD_RAYLIB_CPP_EXAMPLES=OFF"
|
|
||||||
"-DBUILD_TESTING=OFF"
|
|
||||||
# Point CMake to the nixpkgs raylib so it doesn't try to fetch its own
|
|
||||||
"-Draylib_DIR=${pkgs.raylib}/lib/cmake/raylib"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
octree = stdenv.mkDerivation {
|
|
||||||
pname = "octree";
|
|
||||||
version = "2.5-unstable-2025-12-18";
|
|
||||||
|
|
||||||
src = pkgs.fetchFromGitHub {
|
|
||||||
owner = "attcs";
|
|
||||||
repo = "octree";
|
|
||||||
rev = "5058b3090c8b88e405fe2bfddd6c1c872f2b79d2";
|
|
||||||
hash = "sha256-a/aDGQ7cj1GbCjts2s9VEaxyFnL6PF+xJOsSxm9o+4M=";
|
|
||||||
};
|
|
||||||
|
|
||||||
# Header-only library
|
|
||||||
dontBuild = true;
|
|
||||||
installPhase = ''
|
|
||||||
mkdir -p $out/include
|
|
||||||
mv ./*.h $out/include/
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
thread-pool = stdenv.mkDerivation {
|
thread-pool = stdenv.mkDerivation {
|
||||||
pname = "thread-pool";
|
pname = "thread-pool";
|
||||||
@ -130,10 +130,6 @@ rec {
|
|||||||
# Languages:
|
# Languages:
|
||||||
# bintools
|
# bintools
|
||||||
gcc
|
gcc
|
||||||
# clang
|
|
||||||
# bintools_multilib
|
|
||||||
# gcc_multilib
|
|
||||||
# clang_multilib
|
|
||||||
|
|
||||||
# C/C++:
|
# C/C++:
|
||||||
gdb
|
gdb
|
||||||
@ -161,9 +157,9 @@ rec {
|
|||||||
# sfml
|
# sfml
|
||||||
raylib
|
raylib
|
||||||
# octree # this one doesn't store center of mass per node - which I need :(
|
# octree # this one doesn't store center of mass per node - which I need :(
|
||||||
llvmPackages.openmp # not required for compilation but for clangd to find the headers
|
tracy-wayland
|
||||||
tracy
|
|
||||||
thread-pool
|
thread-pool
|
||||||
|
# llvmPackages.openmp # not required for compilation but for clangd to find the headers
|
||||||
# raylib-cpp
|
# raylib-cpp
|
||||||
# tinyobjloader
|
# tinyobjloader
|
||||||
# gperftools
|
# gperftools
|
||||||
@ -235,8 +231,8 @@ rec {
|
|||||||
pkgs.writers.writeFish "cmake-${typeLower}.fish" ''
|
pkgs.writers.writeFish "cmake-${typeLower}.fish" ''
|
||||||
cd $FLAKE_PROJECT_ROOT
|
cd $FLAKE_PROJECT_ROOT
|
||||||
|
|
||||||
# set -g -x CC ${clang}/bin/clang
|
# set -g -x CC ${pkgs.clang}/bin/clang
|
||||||
# set -g -x CXX ${clang}/bin/clang++
|
# set -g -x CXX ${pkgs.clang}/bin/clang++
|
||||||
|
|
||||||
echo "Removing build directory ./cmake-build-${typeLower}/"
|
echo "Removing build directory ./cmake-build-${typeLower}/"
|
||||||
rm -rf ./cmake-build-${typeLower}
|
rm -rf ./cmake-build-${typeLower}
|
||||||
@ -266,7 +262,7 @@ rec {
|
|||||||
cd $FLAKE_PROJECT_ROOT/cmake-build-${typeLower}
|
cd $FLAKE_PROJECT_ROOT/cmake-build-${typeLower}
|
||||||
|
|
||||||
echo "Running cmake"
|
echo "Running cmake"
|
||||||
cmake --build . -j$(nproc)
|
NIX_ENFORCE_NO_NATIVE=0 cmake --build . -j$(nproc)
|
||||||
'';
|
'';
|
||||||
|
|
||||||
buildDebug = mkBuildScript "Debug";
|
buildDebug = mkBuildScript "Debug";
|
||||||
@ -286,6 +282,8 @@ rec {
|
|||||||
abbr -a build-release "${buildRelease}"
|
abbr -a build-release "${buildRelease}"
|
||||||
abbr -a debug "${buildDebug} && ./cmake-build-debug/masssprings"
|
abbr -a debug "${buildDebug} && ./cmake-build-debug/masssprings"
|
||||||
abbr -a release "${buildRelease} && ./cmake-build-release/masssprings"
|
abbr -a release "${buildRelease} && ./cmake-build-release/masssprings"
|
||||||
|
abbr -a rungdb "${buildDebug} && gdb --tui ./cmake-build-debug/masssprings"
|
||||||
|
abbr -a runtracy "tracy -a 127.0.0.1"
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
builtins.concatStringsSep "\n" [
|
builtins.concatStringsSep "\n" [
|
||||||
|
|||||||
@ -26,7 +26,8 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
OrbitCamera3D()
|
OrbitCamera3D()
|
||||||
: camera({0}), position(Vector3Zero()), target(Vector3Zero()),
|
: camera(Camera(Vector3Zero(), Vector3Zero(), Vector3Zero(), 0.0, 0)),
|
||||||
|
position(Vector3Zero()), target(Vector3Zero()),
|
||||||
distance(CAMERA_DISTANCE), angle_x(0.0), angle_y(0.0),
|
distance(CAMERA_DISTANCE), angle_x(0.0), angle_y(0.0),
|
||||||
last_mouse(Vector2Zero()), rotating(false), panning(false),
|
last_mouse(Vector2Zero()), rotating(false), panning(false),
|
||||||
target_lock(true) {
|
target_lock(true) {
|
||||||
|
|||||||
@ -19,8 +19,8 @@ public:
|
|||||||
int block_add_y;
|
int block_add_y;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
InputHandler(StateManager &state, Renderer &renderer)
|
InputHandler(StateManager &_state, Renderer &_renderer)
|
||||||
: state(state), renderer(renderer), hov_x(-1), hov_y(-1), sel_x(0),
|
: state(_state), renderer(_renderer), hov_x(-1), hov_y(-1), sel_x(0),
|
||||||
sel_y(0), has_block_add_xy(false), block_add_x(-1), block_add_y(-1) {}
|
sel_y(0), has_block_add_xy(false), block_add_x(-1), block_add_y(-1) {}
|
||||||
|
|
||||||
InputHandler(const InputHandler ©) = delete;
|
InputHandler(const InputHandler ©) = delete;
|
||||||
|
|||||||
@ -27,9 +27,9 @@ public:
|
|||||||
const bool fixed;
|
const bool fixed;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Mass(float mass, Vector3 position, bool fixed)
|
Mass(float _mass, Vector3 _position, bool _fixed)
|
||||||
: mass(mass), position(position), previous_position(position),
|
: mass(_mass), position(_position), previous_position(_position),
|
||||||
velocity(Vector3Zero()), force(Vector3Zero()), fixed(fixed) {}
|
velocity(Vector3Zero()), force(Vector3Zero()), fixed(_fixed) {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
auto ClearForce() -> void;
|
auto ClearForce() -> void;
|
||||||
@ -50,10 +50,10 @@ public:
|
|||||||
const float rest_length;
|
const float rest_length;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Spring(Mass &massA, Mass &massB, float spring_constant,
|
Spring(Mass &_massA, Mass &_massB, float _spring_constant,
|
||||||
float dampening_constant, float rest_length)
|
float _dampening_constant, float _rest_length)
|
||||||
: massA(massA), massB(massB), spring_constant(spring_constant),
|
: massA(_massA), massB(_massB), spring_constant(_spring_constant),
|
||||||
dampening_constant(dampening_constant), rest_length(rest_length) {}
|
dampening_constant(_dampening_constant), rest_length(_rest_length) {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
auto CalculateSpringForce() const -> void;
|
auto CalculateSpringForce() const -> void;
|
||||||
|
|||||||
@ -31,15 +31,15 @@ public:
|
|||||||
bool target;
|
bool target;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Block(int x, int y, int width, int height, bool target)
|
Block(int _x, int _y, int _width, int _height, bool _target)
|
||||||
: x(x), y(y), width(width), height(height), target(target) {
|
: x(_x), y(_y), width(_width), height(_height), target(_target) {
|
||||||
if (x < 0 || x + width >= 10 || y < 0 || y + height >= 10) {
|
if (_x < 0 || _x + _width >= 10 || _y < 0 || _y + _height >= 10) {
|
||||||
std::cerr << "Block must fit on a 9x9 board!" << std::endl;
|
std::cerr << "Block must fit on a 9x9 board!" << std::endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Block(int x, int y, std::string block) : x(x), y(y) {
|
Block(int _x, int _y, std::string block) : x(_x), y(_y) {
|
||||||
if (block == "..") {
|
if (block == "..") {
|
||||||
this->x = 0;
|
this->x = 0;
|
||||||
this->y = 0;
|
this->y = 0;
|
||||||
@ -68,7 +68,7 @@ public:
|
|||||||
height = std::stoi(block.substr(1, 1));
|
height = std::stoi(block.substr(1, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x < 0 || x + width >= 10 || y < 0 || y + height >= 10) {
|
if (_x < 0 || _x + width >= 10 || _y < 0 || _y + height >= 10) {
|
||||||
std::cerr << "Block must fit on a 9x9 board!" << std::endl;
|
std::cerr << "Block must fit on a 9x9 board!" << std::endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -125,10 +125,10 @@ public:
|
|||||||
int current_pos;
|
int current_pos;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BlockIterator(const State &state) : state(state), current_pos(0) {}
|
BlockIterator(const State &_state) : state(_state), current_pos(0) {}
|
||||||
|
|
||||||
BlockIterator(const State &state, int current_pos)
|
BlockIterator(const State &_state, int _current_pos)
|
||||||
: state(state), current_pos(current_pos) {}
|
: state(_state), current_pos(_current_pos) {}
|
||||||
|
|
||||||
Block operator*() const {
|
Block operator*() const {
|
||||||
return Block(current_pos % state.width, current_pos / state.width,
|
return Block(current_pos % state.width, current_pos / state.width,
|
||||||
@ -150,25 +150,25 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
State(int width, int height, bool restricted)
|
State(int _width, int _height, bool _restricted)
|
||||||
: width(width), height(height), restricted(restricted),
|
: width(_width), height(_height), restricted(_restricted),
|
||||||
state(std::format("{}{}x{}:{}", restricted ? "R" : "F", width, height,
|
state(std::format("{}{}x{}:{}", _restricted ? "R" : "F", _width,
|
||||||
std::string(width * height * 2, '.'))) {
|
_height, std::string(_width * _height * 2, '.'))) {
|
||||||
if (width <= 0 || width >= 10 || height <= 0 || height >= 10) {
|
if (_width <= 0 || _width >= 10 || _height <= 0 || _height >= 10) {
|
||||||
std::cerr << "State width/height must be in [1, 9]!" << std::endl;
|
std::cerr << "State width/height must be in [1, 9]!" << std::endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit State(std::string state)
|
explicit State(std::string _state)
|
||||||
: width(std::stoi(state.substr(1, 1))),
|
: width(std::stoi(_state.substr(1, 1))),
|
||||||
height(std::stoi(state.substr(3, 1))),
|
height(std::stoi(_state.substr(3, 1))),
|
||||||
restricted(state.substr(0, 1) == "R"), state(state) {
|
restricted(_state.substr(0, 1) == "R"), state(_state) {
|
||||||
if (width <= 0 || width >= 10 || height <= 0 || height >= 10) {
|
if (width <= 0 || width >= 10 || height <= 0 || height >= 10) {
|
||||||
std::cerr << "State width/height must be in [1, 9]!" << std::endl;
|
std::cerr << "State width/height must be in [1, 9]!" << std::endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (state.length() != width * height * 2 + 5) {
|
if (static_cast<int>(_state.length()) != width * height * 2 + 5) {
|
||||||
std::cerr
|
std::cerr
|
||||||
<< "State representation must have length [width * height * 2 + 5]!"
|
<< "State representation must have length [width * height * 2 + 5]!"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|||||||
@ -19,7 +19,7 @@ private:
|
|||||||
|
|
||||||
// Instancing
|
// Instancing
|
||||||
Material vertex_mat;
|
Material vertex_mat;
|
||||||
int transforms_size;
|
std::size_t transforms_size;
|
||||||
Matrix *transforms;
|
Matrix *transforms;
|
||||||
Mesh cube_instance;
|
Mesh cube_instance;
|
||||||
Shader instancing_shader;
|
Shader instancing_shader;
|
||||||
@ -29,9 +29,9 @@ public:
|
|||||||
bool connect_solutions;
|
bool connect_solutions;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Renderer(const OrbitCamera3D &camera)
|
Renderer(const OrbitCamera3D &_camera)
|
||||||
: camera(camera), mark_solutions(false), connect_solutions(false),
|
: camera(_camera), transforms_size(0), transforms(nullptr),
|
||||||
transforms_size(0), transforms(nullptr) {
|
mark_solutions(false), connect_solutions(false) {
|
||||||
render_target = LoadRenderTexture(GetScreenWidth() / 2.0,
|
render_target = LoadRenderTexture(GetScreenWidth() / 2.0,
|
||||||
GetScreenHeight() - MENU_HEIGHT);
|
GetScreenHeight() - MENU_HEIGHT);
|
||||||
klotski_target = LoadRenderTexture(GetScreenWidth() / 2.0,
|
klotski_target = LoadRenderTexture(GetScreenWidth() / 2.0,
|
||||||
|
|||||||
@ -13,6 +13,7 @@ public:
|
|||||||
MassSpringSystem &mass_springs;
|
MassSpringSystem &mass_springs;
|
||||||
|
|
||||||
int current_preset;
|
int current_preset;
|
||||||
|
State starting_state;
|
||||||
State current_state;
|
State current_state;
|
||||||
State previous_state;
|
State previous_state;
|
||||||
|
|
||||||
@ -22,10 +23,11 @@ public:
|
|||||||
std::unordered_set<State> visited_states;
|
std::unordered_set<State> visited_states;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StateManager(MassSpringSystem &mass_springs)
|
StateManager(MassSpringSystem &_mass_springs)
|
||||||
: mass_springs(mass_springs), current_preset(0),
|
: mass_springs(_mass_springs), current_preset(0),
|
||||||
current_state(generators[current_preset]()),
|
starting_state(generators[current_preset]()),
|
||||||
previous_state(current_state), edited(false) {
|
current_state(starting_state), previous_state(starting_state),
|
||||||
|
edited(false) {
|
||||||
mass_springs.AddMass(MASS, false, current_state);
|
mass_springs.AddMass(MASS, false, current_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
10
include/tracy.hpp
Normal file
10
include/tracy.hpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef __TRACY_HPP_
|
||||||
|
#define __TRACY_HPP_
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
void *operator new(std::size_t count);
|
||||||
|
void operator delete(void *ptr) noexcept;
|
||||||
|
void operator delete(void *ptr, std::size_t count) noexcept;
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -1,5 +1,6 @@
|
|||||||
#include "camera.hpp"
|
#include "camera.hpp"
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
|
#include "tracy.hpp"
|
||||||
|
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
#include <raymath.h>
|
#include <raymath.h>
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
|
#include "input.hpp"
|
||||||
|
#include "config.hpp"
|
||||||
|
#include "tracy.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
|
|
||||||
#include "config.hpp"
|
|
||||||
#include "input.hpp"
|
|
||||||
|
|
||||||
auto InputHandler::HandleMouseHover() -> void {
|
auto InputHandler::HandleMouseHover() -> void {
|
||||||
const int board_width = GetScreenWidth() / 2.0 - 2 * BOARD_PADDING;
|
const int board_width = GetScreenWidth() / 2.0 - 2 * BOARD_PADDING;
|
||||||
const int board_height = GetScreenHeight() - MENU_HEIGHT - 2 * BOARD_PADDING;
|
const int board_height = GetScreenHeight() - MENU_HEIGHT - 2 * BOARD_PADDING;
|
||||||
|
|||||||
15
src/main.cpp
15
src/main.cpp
@ -1,12 +1,15 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <raylib.h>
|
|
||||||
#include <raymath.h>
|
|
||||||
|
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "input.hpp"
|
#include "input.hpp"
|
||||||
#include "physics.hpp"
|
#include "physics.hpp"
|
||||||
#include "renderer.hpp"
|
#include "renderer.hpp"
|
||||||
#include "state.hpp"
|
#include "state.hpp"
|
||||||
|
#include "tracy.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <raylib.h>
|
||||||
|
#include <raymath.h>
|
||||||
|
#include <tracy/Tracy.hpp>
|
||||||
|
// #include <tracy/TracyOpenGL.hpp>
|
||||||
|
|
||||||
#ifdef PRINT_TIMINGS
|
#ifdef PRINT_TIMINGS
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
@ -38,6 +41,8 @@ auto main(int argc, char *argv[]) -> int {
|
|||||||
SetConfigFlags(FLAG_WINDOW_ALWAYS_RUN);
|
SetConfigFlags(FLAG_WINDOW_ALWAYS_RUN);
|
||||||
InitWindow(INITIAL_WIDTH * 2, INITIAL_HEIGHT + MENU_HEIGHT, "MassSprings");
|
InitWindow(INITIAL_WIDTH * 2, INITIAL_HEIGHT + MENU_HEIGHT, "MassSprings");
|
||||||
|
|
||||||
|
// TracyGpuContext;
|
||||||
|
|
||||||
// Game setup
|
// Game setup
|
||||||
OrbitCamera3D camera;
|
OrbitCamera3D camera;
|
||||||
Renderer renderer(camera);
|
Renderer renderer(camera);
|
||||||
@ -101,7 +106,7 @@ auto main(int argc, char *argv[]) -> int {
|
|||||||
|
|
||||||
renderer.UpdateTextureSizes();
|
renderer.UpdateTextureSizes();
|
||||||
renderer.DrawMassSprings(mass_springs, state.current_state,
|
renderer.DrawMassSprings(mass_springs, state.current_state,
|
||||||
state.CurrentGenerator()(), state.winning_states,
|
state.starting_state, state.winning_states,
|
||||||
state.visited_states);
|
state.visited_states);
|
||||||
|
|
||||||
renderer.DrawKlotski(state.current_state, input.hov_x, input.hov_y,
|
renderer.DrawKlotski(state.current_state, input.hov_x, input.hov_y,
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include "octree.hpp"
|
#include "octree.hpp"
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
|
#include "tracy.hpp"
|
||||||
#include "util.hpp"
|
#include "util.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -131,7 +132,7 @@ auto Octree::CalculateForce(int node_idx, const Vector3 &pos) const -> Vector3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const OctreeNode &node = nodes[node_idx];
|
const OctreeNode &node = nodes[node_idx];
|
||||||
if (node.mass_total == 0.0f) {
|
if (std::abs(node.mass_total) <= 0.001f) {
|
||||||
return Vector3Zero();
|
return Vector3Zero();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
#include "physics.hpp"
|
#include "physics.hpp"
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "util.hpp"
|
#include "tracy.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
|
#include <cstddef>
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
#include <raymath.h>
|
#include <raymath.h>
|
||||||
#include <tracy/Tracy.hpp>
|
#include <tracy/Tracy.hpp>
|
||||||
@ -62,23 +63,19 @@ auto Mass::VerletUpdate(const float delta_time) -> void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto Spring::CalculateSpringForce() const -> void {
|
auto Spring::CalculateSpringForce() const -> void {
|
||||||
Vector3 delta_position;
|
Vector3 delta_position = Vector3Subtract(massA.position, massB.position);
|
||||||
float current_length;
|
float current_length = Vector3Length(delta_position);
|
||||||
Vector3 delta_velocity;
|
float inv_current_length = 1.0 / current_length;
|
||||||
Vector3 force_a;
|
Vector3 delta_velocity = Vector3Subtract(massA.velocity, massB.velocity);
|
||||||
Vector3 force_b;
|
|
||||||
|
|
||||||
delta_position = Vector3Subtract(massA.position, massB.position);
|
|
||||||
current_length = Vector3Length(delta_position);
|
|
||||||
delta_velocity = Vector3Subtract(massA.velocity, massB.velocity);
|
|
||||||
|
|
||||||
float hooke = spring_constant * (current_length - rest_length);
|
float hooke = spring_constant * (current_length - rest_length);
|
||||||
float dampening = dampening_constant *
|
float dampening = dampening_constant *
|
||||||
Vector3DotProduct(delta_velocity, delta_position) /
|
Vector3DotProduct(delta_velocity, delta_position) *
|
||||||
current_length;
|
inv_current_length;
|
||||||
|
|
||||||
force_a = Vector3Scale(delta_position, -(hooke + dampening) / current_length);
|
Vector3 force_a =
|
||||||
force_b = Vector3Scale(force_a, -1.0);
|
Vector3Scale(delta_position, -(hooke + dampening) * inv_current_length);
|
||||||
|
Vector3 force_b = Vector3Scale(force_a, -1.0);
|
||||||
|
|
||||||
massA.force = Vector3Add(massA.force, force_a);
|
massA.force = Vector3Add(massA.force, force_a);
|
||||||
massB.force = Vector3Add(massB.force, force_b);
|
massB.force = Vector3Add(massB.force, force_b);
|
||||||
@ -133,6 +130,8 @@ auto MassSpringSystem::Clear() -> void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto MassSpringSystem::ClearForces() -> void {
|
auto MassSpringSystem::ClearForces() -> void {
|
||||||
|
ZoneScoped;
|
||||||
|
|
||||||
for (auto &[state, mass] : masses) {
|
for (auto &[state, mass] : masses) {
|
||||||
mass.ClearForce();
|
mass.ClearForce();
|
||||||
}
|
}
|
||||||
@ -144,6 +143,20 @@ auto MassSpringSystem::CalculateSpringForces() -> void {
|
|||||||
for (auto &[states, spring] : springs) {
|
for (auto &[states, spring] : springs) {
|
||||||
spring.CalculateSpringForce();
|
spring.CalculateSpringForce();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// spring_pointers.clear();
|
||||||
|
// spring_pointers.reserve(springs.size());
|
||||||
|
// for (auto &[states, spring] : springs) {
|
||||||
|
// spring_pointers.push_back(&spring);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// auto solve_spring = [&](int i) {
|
||||||
|
// spring_pointers[i]->CalculateSpringForce();
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// BS::multi_future<void> loop_future =
|
||||||
|
// threads.submit_loop(0, spring_pointers.size(), solve_spring, 4096);
|
||||||
|
// loop_future.wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BARNES_HUT
|
#ifdef BARNES_HUT
|
||||||
@ -184,7 +197,7 @@ auto MassSpringSystem::BuildOctree() -> void {
|
|||||||
for (auto &[state, mass] : masses) {
|
for (auto &[state, mass] : masses) {
|
||||||
mass_pointers.push_back(&mass);
|
mass_pointers.push_back(&mass);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < mass_pointers.size(); ++i) {
|
for (std::size_t i = 0; i < mass_pointers.size(); ++i) {
|
||||||
octree.Insert(root, i, mass_pointers[i]->position, mass_pointers[i]->mass);
|
octree.Insert(root, i, mass_pointers[i]->position, mass_pointers[i]->mass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,7 +320,7 @@ auto MassSpringSystem::CalculateRepulsionForces() -> void {
|
|||||||
Vector3 direction =
|
Vector3 direction =
|
||||||
Vector3Subtract(mass->position, neighbor->position);
|
Vector3Subtract(mass->position, neighbor->position);
|
||||||
float distance = Vector3Length(direction);
|
float distance = Vector3Length(direction);
|
||||||
if (distance == 0.0f || distance >= REPULSION_RANGE) {
|
if (std::abs(distance) <= 0.001f || distance >= REPULSION_RANGE) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
#include "puzzle.hpp"
|
#include "puzzle.hpp"
|
||||||
|
#include "tracy.hpp"
|
||||||
|
|
||||||
auto Block::Hash() const -> int {
|
auto Block::Hash() const -> int {
|
||||||
std::string s = std::format("{},{},{},{}", x, y, width, height);
|
std::string s = std::format("{},{},{},{}", x, y, width, height);
|
||||||
@ -144,12 +145,11 @@ auto State::ToggleTarget(int x, int y) -> bool {
|
|||||||
|
|
||||||
// Remove the current target
|
// Remove the current target
|
||||||
int index;
|
int index;
|
||||||
for (const auto &block : *this) {
|
for (const auto &b : *this) {
|
||||||
if (block.target) {
|
if (b.target) {
|
||||||
index = GetIndex(block.x, block.y);
|
index = GetIndex(b.x, b.y);
|
||||||
state.replace(
|
state.replace(index, 2,
|
||||||
index, 2,
|
Block(b.x, b.y, b.width, b.height, false).ToString());
|
||||||
Block(block.x, block.y, block.width, block.height, false).ToString());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,8 @@
|
|||||||
#include "renderer.hpp"
|
#include "renderer.hpp"
|
||||||
|
#include "config.hpp"
|
||||||
|
#include "physics.hpp"
|
||||||
|
#include "puzzle.hpp"
|
||||||
|
#include "tracy.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <format>
|
#include <format>
|
||||||
@ -8,10 +12,6 @@
|
|||||||
#include <tracy/Tracy.hpp>
|
#include <tracy/Tracy.hpp>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
#include "config.hpp"
|
|
||||||
#include "physics.hpp"
|
|
||||||
#include "puzzle.hpp"
|
|
||||||
|
|
||||||
#ifdef BATCHING
|
#ifdef BATCHING
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#endif
|
#endif
|
||||||
@ -314,4 +314,5 @@ auto Renderer::DrawTextures() -> void {
|
|||||||
Vector2(GetScreenWidth() / 2.0, MENU_HEIGHT), WHITE);
|
Vector2(GetScreenWidth() / 2.0, MENU_HEIGHT), WHITE);
|
||||||
DrawFPS(GetScreenWidth() / 2 + 10, MENU_HEIGHT + 10);
|
DrawFPS(GetScreenWidth() / 2 + 10, MENU_HEIGHT + 10);
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
FrameMark;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#include "state.hpp"
|
#include "state.hpp"
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "presets.hpp"
|
#include "presets.hpp"
|
||||||
|
#include "tracy.hpp"
|
||||||
|
|
||||||
#include <raymath.h>
|
#include <raymath.h>
|
||||||
|
|
||||||
@ -76,6 +77,9 @@ auto StateManager::ClearGraph() -> void {
|
|||||||
|
|
||||||
// The previous_state is no longer in the graph
|
// The previous_state is no longer in the graph
|
||||||
previous_state = current_state;
|
previous_state = current_state;
|
||||||
|
|
||||||
|
// The starting state is no longer in the graph
|
||||||
|
starting_state = current_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto StateManager::FindWinningStates() -> void {
|
auto StateManager::FindWinningStates() -> void {
|
||||||
|
|||||||
17
src/tracy.cpp
Normal file
17
src/tracy.cpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#include "tracy.hpp"
|
||||||
|
|
||||||
|
#include <tracy/Tracy.hpp>
|
||||||
|
|
||||||
|
void *operator new(std::size_t count) {
|
||||||
|
auto ptr = malloc(count);
|
||||||
|
TracyAlloc(ptr, count);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
void operator delete(void *ptr) noexcept {
|
||||||
|
TracyFree(ptr);
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
|
void operator delete(void *ptr, std::size_t count) noexcept {
|
||||||
|
TracyFree(ptr);
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user