update compiler flags, fix tracy allocation profiling, fix compiler warnings
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
#include "camera.hpp"
|
||||
#include "config.hpp"
|
||||
#include "tracy.hpp"
|
||||
|
||||
#include <raylib.h>
|
||||
#include <raymath.h>
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
#include "input.hpp"
|
||||
#include "config.hpp"
|
||||
#include "tracy.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <raylib.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "input.hpp"
|
||||
|
||||
auto InputHandler::HandleMouseHover() -> void {
|
||||
const int board_width = GetScreenWidth() / 2.0 - 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 "input.hpp"
|
||||
#include "physics.hpp"
|
||||
#include "renderer.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
|
||||
#include <chrono>
|
||||
@ -38,6 +41,8 @@ auto main(int argc, char *argv[]) -> int {
|
||||
SetConfigFlags(FLAG_WINDOW_ALWAYS_RUN);
|
||||
InitWindow(INITIAL_WIDTH * 2, INITIAL_HEIGHT + MENU_HEIGHT, "MassSprings");
|
||||
|
||||
// TracyGpuContext;
|
||||
|
||||
// Game setup
|
||||
OrbitCamera3D camera;
|
||||
Renderer renderer(camera);
|
||||
@ -101,7 +106,7 @@ auto main(int argc, char *argv[]) -> int {
|
||||
|
||||
renderer.UpdateTextureSizes();
|
||||
renderer.DrawMassSprings(mass_springs, state.current_state,
|
||||
state.CurrentGenerator()(), state.winning_states,
|
||||
state.starting_state, state.winning_states,
|
||||
state.visited_states);
|
||||
|
||||
renderer.DrawKlotski(state.current_state, input.hov_x, input.hov_y,
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#include "octree.hpp"
|
||||
#include "config.hpp"
|
||||
#include "tracy.hpp"
|
||||
#include "util.hpp"
|
||||
|
||||
#include <iostream>
|
||||
@ -131,7 +132,7 @@ auto Octree::CalculateForce(int node_idx, const Vector3 &pos) const -> Vector3 {
|
||||
}
|
||||
|
||||
const OctreeNode &node = nodes[node_idx];
|
||||
if (node.mass_total == 0.0f) {
|
||||
if (std::abs(node.mass_total) <= 0.001f) {
|
||||
return Vector3Zero();
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
#include "physics.hpp"
|
||||
#include "config.hpp"
|
||||
#include "util.hpp"
|
||||
#include "tracy.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cfloat>
|
||||
#include <cstddef>
|
||||
#include <raylib.h>
|
||||
#include <raymath.h>
|
||||
#include <tracy/Tracy.hpp>
|
||||
@ -62,23 +63,19 @@ auto Mass::VerletUpdate(const float delta_time) -> void {
|
||||
}
|
||||
|
||||
auto Spring::CalculateSpringForce() const -> void {
|
||||
Vector3 delta_position;
|
||||
float current_length;
|
||||
Vector3 delta_velocity;
|
||||
Vector3 force_a;
|
||||
Vector3 force_b;
|
||||
|
||||
delta_position = Vector3Subtract(massA.position, massB.position);
|
||||
current_length = Vector3Length(delta_position);
|
||||
delta_velocity = Vector3Subtract(massA.velocity, massB.velocity);
|
||||
Vector3 delta_position = Vector3Subtract(massA.position, massB.position);
|
||||
float current_length = Vector3Length(delta_position);
|
||||
float inv_current_length = 1.0 / current_length;
|
||||
Vector3 delta_velocity = Vector3Subtract(massA.velocity, massB.velocity);
|
||||
|
||||
float hooke = spring_constant * (current_length - rest_length);
|
||||
float dampening = dampening_constant *
|
||||
Vector3DotProduct(delta_velocity, delta_position) /
|
||||
current_length;
|
||||
Vector3DotProduct(delta_velocity, delta_position) *
|
||||
inv_current_length;
|
||||
|
||||
force_a = Vector3Scale(delta_position, -(hooke + dampening) / current_length);
|
||||
force_b = Vector3Scale(force_a, -1.0);
|
||||
Vector3 force_a =
|
||||
Vector3Scale(delta_position, -(hooke + dampening) * inv_current_length);
|
||||
Vector3 force_b = Vector3Scale(force_a, -1.0);
|
||||
|
||||
massA.force = Vector3Add(massA.force, force_a);
|
||||
massB.force = Vector3Add(massB.force, force_b);
|
||||
@ -133,6 +130,8 @@ auto MassSpringSystem::Clear() -> void {
|
||||
}
|
||||
|
||||
auto MassSpringSystem::ClearForces() -> void {
|
||||
ZoneScoped;
|
||||
|
||||
for (auto &[state, mass] : masses) {
|
||||
mass.ClearForce();
|
||||
}
|
||||
@ -144,6 +143,20 @@ auto MassSpringSystem::CalculateSpringForces() -> void {
|
||||
for (auto &[states, spring] : springs) {
|
||||
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
|
||||
@ -184,7 +197,7 @@ auto MassSpringSystem::BuildOctree() -> void {
|
||||
for (auto &[state, mass] : masses) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -307,7 +320,7 @@ auto MassSpringSystem::CalculateRepulsionForces() -> void {
|
||||
Vector3 direction =
|
||||
Vector3Subtract(mass->position, neighbor->position);
|
||||
float distance = Vector3Length(direction);
|
||||
if (distance == 0.0f || distance >= REPULSION_RANGE) {
|
||||
if (std::abs(distance) <= 0.001f || distance >= REPULSION_RANGE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
#include "puzzle.hpp"
|
||||
#include "tracy.hpp"
|
||||
|
||||
auto Block::Hash() const -> int {
|
||||
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
|
||||
int index;
|
||||
for (const auto &block : *this) {
|
||||
if (block.target) {
|
||||
index = GetIndex(block.x, block.y);
|
||||
state.replace(
|
||||
index, 2,
|
||||
Block(block.x, block.y, block.width, block.height, false).ToString());
|
||||
for (const auto &b : *this) {
|
||||
if (b.target) {
|
||||
index = GetIndex(b.x, b.y);
|
||||
state.replace(index, 2,
|
||||
Block(b.x, b.y, b.width, b.height, false).ToString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,8 @@
|
||||
#include "renderer.hpp"
|
||||
#include "config.hpp"
|
||||
#include "physics.hpp"
|
||||
#include "puzzle.hpp"
|
||||
#include "tracy.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <format>
|
||||
@ -8,10 +12,6 @@
|
||||
#include <tracy/Tracy.hpp>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "physics.hpp"
|
||||
#include "puzzle.hpp"
|
||||
|
||||
#ifdef BATCHING
|
||||
#include <cstring>
|
||||
#endif
|
||||
@ -314,4 +314,5 @@ auto Renderer::DrawTextures() -> void {
|
||||
Vector2(GetScreenWidth() / 2.0, MENU_HEIGHT), WHITE);
|
||||
DrawFPS(GetScreenWidth() / 2 + 10, MENU_HEIGHT + 10);
|
||||
EndDrawing();
|
||||
FrameMark;
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#include "state.hpp"
|
||||
#include "config.hpp"
|
||||
#include "presets.hpp"
|
||||
#include "tracy.hpp"
|
||||
|
||||
#include <raymath.h>
|
||||
|
||||
@ -76,6 +77,9 @@ auto StateManager::ClearGraph() -> void {
|
||||
|
||||
// The previous_state is no longer in the graph
|
||||
previous_state = current_state;
|
||||
|
||||
// The starting state is no longer in the graph
|
||||
starting_state = current_state;
|
||||
}
|
||||
|
||||
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