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:
@@ -1829,7 +1829,7 @@ void Engine::activateShapeInternal(ShapeType type) {
|
||||
active_shape_ = std::make_unique<AtomShape>();
|
||||
break;
|
||||
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;
|
||||
default:
|
||||
active_shape_ = std::make_unique<SphereShape>(); // Fallback
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "png_shape.hpp"
|
||||
#include "defines.hpp"
|
||||
#include "external/stb_image.h"
|
||||
#include "resource_manager.hpp"
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#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);
|
||||
}
|
||||
|
||||
bool PNGShape::loadPNG(const char* path) {
|
||||
std::cout << "[PNGShape] Intentando cargar: " << path << std::endl;
|
||||
int width, height, channels;
|
||||
unsigned char* data = stbi_load(path, &width, &height, &channels, 1); // Forzar 1 canal (grayscale)
|
||||
|
||||
if (!data) {
|
||||
std::cerr << "[PNGShape] ERROR al cargar PNG: " << stbi_failure_reason() << std::endl;
|
||||
bool PNGShape::loadPNG(const char* resource_key) {
|
||||
std::cout << "[PNGShape] Cargando recurso: " << resource_key << std::endl;
|
||||
unsigned char* file_data = nullptr;
|
||||
size_t file_size = 0;
|
||||
if (!ResourceManager::loadResource(resource_key, file_data, file_size)) {
|
||||
std::cerr << "[PNGShape] ERROR: recurso no encontrado: " << resource_key << 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;
|
||||
}
|
||||
|
||||
image_width_ = width;
|
||||
image_height_ = 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++) {
|
||||
pixel_data_[i] = (data[i] > 128); // Umbral: >128 = blanco
|
||||
pixel_data_[i] = (pixels[i] > 128);
|
||||
}
|
||||
|
||||
stbi_image_free(data);
|
||||
stbi_image_free(pixels);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -269,7 +269,7 @@ void ShapeManager::activateShapeInternal(ShapeType type) {
|
||||
active_shape_ = std::make_unique<AtomShape>();
|
||||
break;
|
||||
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;
|
||||
default:
|
||||
active_shape_ = std::make_unique<SphereShape>(); // Fallback
|
||||
|
||||
Reference in New Issue
Block a user