Fix: Carga de recursos en macOS Bundle + limpieza Makefile
- Arreglar getExecutableDirectory() para usar _NSGetExecutablePath en macOS - Añadir getResourcesDirectory() con soporte MACOS_BUNDLE - Actualizar main.cpp y engine.cpp para buscar recursos correctamente - Eliminar referencias obsoletas a directorio 'config' en Makefile Ahora resources.pack se busca en ../Resources/ cuando MACOS_BUNDLE está definido, permitiendo que la app bundle funcione correctamente. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
5
Makefile
5
Makefile
@@ -183,7 +183,6 @@ macos_release: resources.pack
|
||||
$(MKDIR) Frameworks
|
||||
|
||||
# Copia carpetas y ficheros
|
||||
cp -R config "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources"
|
||||
cp resources.pack "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources"
|
||||
cp -R release/frameworks/SDL3.xcframework "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Frameworks"
|
||||
cp -R release/frameworks/SDL3.xcframework Frameworks
|
||||
@@ -243,7 +242,6 @@ linux_release: resources.pack
|
||||
$(MKDIR) "$(RELEASE_FOLDER)"
|
||||
|
||||
# Copia ficheros
|
||||
cp -R config "$(RELEASE_FOLDER)"
|
||||
cp resources.pack "$(RELEASE_FOLDER)"
|
||||
cp LICENSE "$(RELEASE_FOLDER)"
|
||||
cp README.md "$(RELEASE_FOLDER)"
|
||||
@@ -273,7 +271,6 @@ linux_release_desktop: resources.pack
|
||||
$(MKDIR) "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/$(TARGET_NAME)"
|
||||
|
||||
# Copia ficheros del juego
|
||||
cp -R config "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/$(TARGET_NAME)/"
|
||||
cp resources.pack "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/$(TARGET_NAME)/"
|
||||
cp LICENSE "$(RELEASE_FOLDER)/$(TARGET_NAME)/"
|
||||
cp README.md "$(RELEASE_FOLDER)/$(TARGET_NAME)/"
|
||||
@@ -374,7 +371,6 @@ raspi_release: resources.pack
|
||||
$(MKDIR) "$(RELEASE_FOLDER)"
|
||||
|
||||
# Copia ficheros
|
||||
cp -R config "$(RELEASE_FOLDER)"
|
||||
cp resources.pack "$(RELEASE_FOLDER)"
|
||||
cp LICENSE "$(RELEASE_FOLDER)"
|
||||
cp README.md "$(RELEASE_FOLDER)"
|
||||
@@ -400,7 +396,6 @@ anbernic: resources.pack
|
||||
$(MKDIR) "$(RELEASE_FOLDER)"_anbernic
|
||||
|
||||
# Copia ficheros
|
||||
cp -R config "$(RELEASE_FOLDER)"_anbernic
|
||||
cp resources.pack "$(RELEASE_FOLDER)"_anbernic
|
||||
|
||||
# Compila
|
||||
|
||||
@@ -231,6 +231,9 @@ constexpr float PI = 3.14159265358979323846f; // Constante PI
|
||||
#include <filesystem>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#elif defined(__APPLE__)
|
||||
#include <mach-o/dyld.h>
|
||||
#include <limits.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
@@ -242,7 +245,16 @@ inline std::string getExecutableDirectory() {
|
||||
GetModuleFileNameA(NULL, buffer, MAX_PATH);
|
||||
std::filesystem::path exe_path(buffer);
|
||||
return exe_path.parent_path().string();
|
||||
#elif defined(__APPLE__)
|
||||
char buffer[PATH_MAX];
|
||||
uint32_t size = sizeof(buffer);
|
||||
if (_NSGetExecutablePath(buffer, &size) == 0) {
|
||||
std::filesystem::path exe_path(buffer);
|
||||
return exe_path.parent_path().string();
|
||||
}
|
||||
return ".";
|
||||
#else
|
||||
// Linux y otros Unix
|
||||
char buffer[PATH_MAX];
|
||||
ssize_t len = readlink("/proc/self/exe", buffer, sizeof(buffer) - 1);
|
||||
if (len != -1) {
|
||||
@@ -253,3 +265,17 @@ inline std::string getExecutableDirectory() {
|
||||
return ".";
|
||||
#endif
|
||||
}
|
||||
|
||||
// Función auxiliar para obtener la ruta del directorio de recursos
|
||||
inline std::string getResourcesDirectory() {
|
||||
std::string exe_dir = getExecutableDirectory();
|
||||
|
||||
#ifdef MACOS_BUNDLE
|
||||
// En macOS Bundle: ejecutable está en Contents/MacOS/, recursos en Contents/Resources/
|
||||
std::filesystem::path resources_path = std::filesystem::path(exe_dir) / ".." / "Resources";
|
||||
return resources_path.string();
|
||||
#else
|
||||
// En desarrollo o releases normales: recursos están junto al ejecutable
|
||||
return exe_dir;
|
||||
#endif
|
||||
}
|
||||
@@ -128,8 +128,8 @@ bool Engine::initialize(int width, int height, int zoom, bool fullscreen) {
|
||||
// Inicializar otros componentes si SDL se inicializó correctamente
|
||||
if (success) {
|
||||
// Cargar todas las texturas disponibles desde data/balls/
|
||||
std::string exe_dir = getExecutableDirectory();
|
||||
std::string balls_dir = exe_dir + "/data/balls";
|
||||
std::string resources_dir = getResourcesDirectory();
|
||||
std::string balls_dir = resources_dir + "/data/balls";
|
||||
|
||||
struct TextureInfo {
|
||||
std::string name;
|
||||
|
||||
@@ -75,8 +75,8 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
// Inicializar sistema de recursos empaquetados (intentar cargar resources.pack)
|
||||
std::string exe_dir = getExecutableDirectory();
|
||||
std::string pack_path = exe_dir + "/resources.pack";
|
||||
std::string resources_dir = getResourcesDirectory();
|
||||
std::string pack_path = resources_dir + "/resources.pack";
|
||||
Texture::initResourceSystem(pack_path);
|
||||
|
||||
Engine engine;
|
||||
|
||||
Reference in New Issue
Block a user