fix: png_shape ja carrega de resources.pack

Amb tots els fixos anteriors, el app de macos ja funciona correctament
This commit is contained in:
2026-03-08 22:36:10 +01:00
parent b9264c96a1
commit a65544e8b3
4 changed files with 24 additions and 15 deletions

View File

@@ -59,3 +59,8 @@ set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAK
# Enlazar las bibliotecas necesarias # Enlazar las bibliotecas necesarias
target_link_libraries(${PROJECT_NAME} ${LINK_LIBS}) target_link_libraries(${PROJECT_NAME} ${LINK_LIBS})
# Tool: pack_resources
add_executable(pack_resources tools/pack_resources.cpp source/resource_pack.cpp)
target_include_directories(pack_resources PRIVATE ${CMAKE_SOURCE_DIR}/source)
set_target_properties(pack_resources PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tools")

View File

@@ -1829,7 +1829,7 @@ void Engine::activateShapeInternal(ShapeType type) {
active_shape_ = std::make_unique<AtomShape>(); active_shape_ = std::make_unique<AtomShape>();
break; break;
case ShapeType::PNG_SHAPE: case ShapeType::PNG_SHAPE:
active_shape_ = std::make_unique<PNGShape>((getResourcesDirectory() + "/data/shapes/jailgames.png").c_str()); active_shape_ = std::make_unique<PNGShape>("shapes/jailgames.png");
break; break;
default: default:
active_shape_ = std::make_unique<SphereShape>(); // Fallback active_shape_ = std::make_unique<SphereShape>(); // Fallback

View File

@@ -1,6 +1,7 @@
#include "png_shape.hpp" #include "png_shape.hpp"
#include "defines.hpp" #include "defines.hpp"
#include "external/stb_image.h" #include "external/stb_image.h"
#include "resource_manager.hpp"
#include <cmath> #include <cmath>
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
@@ -20,26 +21,29 @@ PNGShape::PNGShape(const char* png_path) {
next_idle_time_ = PNG_IDLE_TIME_MIN + (rand() % 1000) / 1000.0f * (PNG_IDLE_TIME_MAX - PNG_IDLE_TIME_MIN); next_idle_time_ = PNG_IDLE_TIME_MIN + (rand() % 1000) / 1000.0f * (PNG_IDLE_TIME_MAX - PNG_IDLE_TIME_MIN);
} }
bool PNGShape::loadPNG(const char* path) { bool PNGShape::loadPNG(const char* resource_key) {
std::cout << "[PNGShape] Intentando cargar: " << path << std::endl; std::cout << "[PNGShape] Cargando recurso: " << resource_key << std::endl;
int width, height, channels; unsigned char* file_data = nullptr;
unsigned char* data = stbi_load(path, &width, &height, &channels, 1); // Forzar 1 canal (grayscale) size_t file_size = 0;
if (!ResourceManager::loadResource(resource_key, file_data, file_size)) {
if (!data) { std::cerr << "[PNGShape] ERROR: recurso no encontrado: " << resource_key << std::endl;
std::cerr << "[PNGShape] ERROR al cargar PNG: " << stbi_failure_reason() << std::endl; return false;
}
int width, height, channels;
unsigned char* pixels = stbi_load_from_memory(file_data, static_cast<int>(file_size),
&width, &height, &channels, 1);
delete[] file_data;
if (!pixels) {
std::cerr << "[PNGShape] ERROR al decodificar PNG: " << stbi_failure_reason() << std::endl;
return false; return false;
} }
image_width_ = width; image_width_ = width;
image_height_ = height; image_height_ = height;
pixel_data_.resize(width * height); pixel_data_.resize(width * height);
// Convertir a mapa booleano (true = píxel blanco/visible, false = negro/transparente)
for (int i = 0; i < width * height; i++) { for (int i = 0; i < width * height; i++) {
pixel_data_[i] = (data[i] > 128); // Umbral: >128 = blanco pixel_data_[i] = (pixels[i] > 128);
} }
stbi_image_free(pixels);
stbi_image_free(data);
return true; return true;
} }

View File

@@ -269,7 +269,7 @@ void ShapeManager::activateShapeInternal(ShapeType type) {
active_shape_ = std::make_unique<AtomShape>(); active_shape_ = std::make_unique<AtomShape>();
break; break;
case ShapeType::PNG_SHAPE: case ShapeType::PNG_SHAPE:
active_shape_ = std::make_unique<PNGShape>((getResourcesDirectory() + "/data/shapes/jailgames.png").c_str()); active_shape_ = std::make_unique<PNGShape>("shapes/jailgames.png");
break; break;
default: default:
active_shape_ = std::make_unique<SphereShape>(); // Fallback active_shape_ = std::make_unique<SphereShape>(); // Fallback