diff --git a/source/defines.h b/source/defines.h index a3177e2..3e204e2 100644 --- a/source/defines.h +++ b/source/defines.h @@ -225,4 +225,31 @@ constexpr float LOGO_CONVERGENCE_DISTANCE = 20.0f; // Distancia (px) para con constexpr int LOGO_JUMP_PROBABILITY_FROM_DEMO = 5; // 5% probabilidad en DEMO normal (más raro) constexpr int LOGO_JUMP_PROBABILITY_FROM_DEMO_LITE = 3; // 3% probabilidad en DEMO LITE (aún más raro) -constexpr float PI = 3.14159265358979323846f; // Constante PI \ No newline at end of file +constexpr float PI = 3.14159265358979323846f; // Constante PI + +// Función auxiliar para obtener la ruta del directorio del ejecutable +#include +#ifdef _WIN32 +#include +#else +#include +#include +#endif + +inline std::string getExecutableDirectory() { +#ifdef _WIN32 + char buffer[MAX_PATH]; + GetModuleFileNameA(NULL, buffer, MAX_PATH); + std::filesystem::path exe_path(buffer); + return exe_path.parent_path().string(); +#else + char buffer[PATH_MAX]; + ssize_t len = readlink("/proc/self/exe", buffer, sizeof(buffer) - 1); + if (len != -1) { + buffer[len] = '\0'; + std::filesystem::path exe_path(buffer); + return exe_path.parent_path().string(); + } + return "."; +#endif +} \ No newline at end of file diff --git a/source/engine.cpp b/source/engine.cpp index f37dd8b..4f333c4 100644 --- a/source/engine.cpp +++ b/source/engine.cpp @@ -35,18 +35,7 @@ #include "shapes/torus_shape.h" // for TorusShape #include "shapes/wave_grid_shape.h" // for WaveGridShape -// Función auxiliar para obtener la ruta del directorio del ejecutable -std::string getExecutableDirectory() { -#ifdef _WIN32 - char buffer[MAX_PATH]; - GetModuleFileNameA(NULL, buffer, MAX_PATH); - std::filesystem::path exe_path(buffer); - return exe_path.parent_path().string(); -#else - // Para Linux/macOS se podría usar readlink("/proc/self/exe") o dladdr - return "."; // Fallback para otros sistemas -#endif -} +// getExecutableDirectory() ya está definido en defines.h como inline // Implementación de métodos públicos bool Engine::initialize(int width, int height, int zoom, bool fullscreen) { diff --git a/source/main.cpp b/source/main.cpp index 6d68994..6f218bf 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -2,6 +2,8 @@ #include #include "engine.h" +// getExecutableDirectory() ya está definido en defines.h como inline + void printHelp() { std::cout << "ViBe3 Physics - Simulador de físicas avanzadas\n"; std::cout << "\nUso: vibe3_physics [opciones]\n\n"; @@ -73,7 +75,9 @@ int main(int argc, char* argv[]) { } // Inicializar sistema de recursos empaquetados (intentar cargar resources.pack) - Texture::initResourceSystem("resources.pack"); + std::string exe_dir = getExecutableDirectory(); + std::string pack_path = exe_dir + "/resources.pack"; + Texture::initResourceSystem(pack_path); Engine engine;