arreglat el cuelgue de la precàrrega en wasm i afegit nom del recurs en curs
- CMakeLists.txt (Emscripten): afegit -fexceptions (compile + link) perquè fkyaml i altres throws ara es capturen pels try/catch enlloc de cridar abort(). També -sASSERTIONS=1 per veure missatges clars d'error en el runtime de Emscripten. - resource_cache: abans de carregar cada recurs, desa el seu nom en current_loading_name_ i (en wasm/debug) el repinta immediatament sobre la barra de progrés. Ara, si la càrrega es penja en un fitxer concret, el nom queda visible en pantalla i ajuda a diagnosticar el problema. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -226,6 +226,7 @@ namespace Resource {
|
||||
for (const auto& l : list) {
|
||||
try {
|
||||
auto name = getFileName(l);
|
||||
setCurrentLoading(name);
|
||||
JA_Sound_t* sound = nullptr;
|
||||
|
||||
// Try loading from resource pack first
|
||||
@@ -261,6 +262,7 @@ namespace Resource {
|
||||
for (const auto& l : list) {
|
||||
try {
|
||||
auto name = getFileName(l);
|
||||
setCurrentLoading(name);
|
||||
JA_Music_t* music = nullptr;
|
||||
|
||||
// Try loading from resource pack first
|
||||
@@ -296,6 +298,7 @@ namespace Resource {
|
||||
for (const auto& l : list) {
|
||||
try {
|
||||
auto name = getFileName(l);
|
||||
setCurrentLoading(name);
|
||||
surfaces_.emplace_back(SurfaceResource{.name = name, .surface = std::make_shared<Surface>(l)});
|
||||
surfaces_.back().surface->setTransparentColor(0);
|
||||
updateLoadingProgress();
|
||||
@@ -323,6 +326,7 @@ namespace Resource {
|
||||
for (const auto& l : list) {
|
||||
try {
|
||||
auto name = getFileName(l);
|
||||
setCurrentLoading(name);
|
||||
palettes_.emplace_back(ResourcePalette{.name = name, .palette = readPalFile(l)});
|
||||
updateLoadingProgress();
|
||||
} catch (const std::exception& e) {
|
||||
@@ -340,6 +344,7 @@ namespace Resource {
|
||||
for (const auto& l : list) {
|
||||
try {
|
||||
auto name = getFileName(l);
|
||||
setCurrentLoading(name);
|
||||
text_files_.emplace_back(TextFileResource{.name = name, .text_file = Text::loadTextFile(l)});
|
||||
updateLoadingProgress();
|
||||
} catch (const std::exception& e) {
|
||||
@@ -357,6 +362,7 @@ namespace Resource {
|
||||
for (const auto& l : list) {
|
||||
try {
|
||||
auto name = getFileName(l);
|
||||
setCurrentLoading(name);
|
||||
|
||||
// Cargar bytes del archivo YAML sin parsear (carga lazy)
|
||||
auto yaml_bytes = Helper::loadFile(l);
|
||||
@@ -383,6 +389,7 @@ namespace Resource {
|
||||
for (const auto& l : list) {
|
||||
try {
|
||||
auto name = getFileName(l);
|
||||
setCurrentLoading(name);
|
||||
rooms_.emplace_back(RoomResource{.name = name, .room = std::make_shared<Room::Data>(Room::loadYAML(l))});
|
||||
printWithDots("Room : ", name, "[ LOADED ]");
|
||||
updateLoadingProgress();
|
||||
@@ -501,9 +508,31 @@ namespace Resource {
|
||||
SDL_FRect rect_full = {.x = X_PADDING, .y = BAR_POSITION, .w = FULL_BAR_WIDTH, .h = BAR_HEIGHT};
|
||||
surface->fillRect(&rect_full, BAR_COLOR);
|
||||
|
||||
#if defined(__EMSCRIPTEN__) || defined(_DEBUG)
|
||||
// Mostra el nom del recurs que està a punt de carregar-se, centrat sobre la barra
|
||||
if (!current_loading_name_.empty()) {
|
||||
const float TEXT_Y = BAR_POSITION - static_cast<float>(TEXT_HEIGHT) - 2.0F;
|
||||
loading_text_->writeColored(
|
||||
CENTER_X - (loading_text_->length(current_loading_name_) / 2),
|
||||
static_cast<int>(TEXT_Y),
|
||||
current_loading_name_,
|
||||
LOADING_TEXT_COLOR);
|
||||
}
|
||||
#endif
|
||||
|
||||
Screen::get()->render();
|
||||
}
|
||||
|
||||
// Desa el nom del recurs que s'està a punt de carregar i repinta immediatament.
|
||||
// A wasm/debug serveix per veure exactament en quin fitxer es penja la càrrega.
|
||||
void Cache::setCurrentLoading(const std::string& name) {
|
||||
current_loading_name_ = name;
|
||||
#if defined(__EMSCRIPTEN__) || defined(_DEBUG)
|
||||
renderProgress();
|
||||
checkEvents();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Comprueba los eventos de la pantalla de carga
|
||||
void Cache::checkEvents() {
|
||||
SDL_Event event;
|
||||
|
||||
@@ -68,6 +68,7 @@ namespace Resource {
|
||||
void renderProgress();
|
||||
static void checkEvents();
|
||||
void updateLoadingProgress(int steps = 5);
|
||||
void setCurrentLoading(const std::string& name); // Desa el nom del recurs en curs i repinta (wasm/debug)
|
||||
|
||||
// Helper para mensajes de error de carga
|
||||
[[noreturn]] static void throwLoadError(const std::string& asset_type, const std::string& file_path, const std::exception& e);
|
||||
@@ -91,6 +92,7 @@ namespace Resource {
|
||||
|
||||
ResourceCount count_{}; // Contador de recursos
|
||||
std::shared_ptr<Text> loading_text_; // Texto para la pantalla de carga
|
||||
std::string current_loading_name_; // Nom del recurs que s'està a punt de carregar (debug/wasm)
|
||||
};
|
||||
|
||||
} // namespace Resource
|
||||
|
||||
Reference in New Issue
Block a user