From e318410bff02a7b6cd63f2e308b0b0ebc78cc2e7 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Thu, 7 Apr 2022 21:06:47 +0200 Subject: [PATCH] improved handling of missing models/images --- rogueviz/objmodels.cpp | 2 +- rogueviz/playing-with-impossibility.cpp | 13 +++++++++++-- rogueviz/presentation.cpp | 5 ++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/rogueviz/objmodels.cpp b/rogueviz/objmodels.cpp index cd6d89a9..77eb3de0 100644 --- a/rogueviz/objmodels.cpp +++ b/rogueviz/objmodels.cpp @@ -17,7 +17,7 @@ char peek(fhstream& fs) { bool model::available() { if(av_checked) return is_available; av_checked = true; - is_available = false; + is_available = file_exists(path + fname); return false; } diff --git a/rogueviz/playing-with-impossibility.cpp b/rogueviz/playing-with-impossibility.cpp index 571e0117..0439f6c2 100644 --- a/rogueviz/playing-with-impossibility.cpp +++ b/rogueviz/playing-with-impossibility.cpp @@ -1015,10 +1015,19 @@ slide dmv_slides[] = { "(the animation is not included with RogueViz)" , [] (presmode mode) { + static bool pic_exists, video_exists; + if(mode == pmStartAll || mode == pmStart) { + pic_exists = file_exists("rogueviz/nil/emty-ring.png"); + video_exists = file_exists("rogueviz/nil/emty-ring.mp4"); + } slide_url(mode, 'i', "Instagram link", "https://www.instagram.com/p/B756GCynErw/"); empty_screen(mode); - // show_picture(mode, "rogueviz/nil/emty-ring.png"); - // show_animation(mode, "rogueviz/nil/emty-ring.mp4", 720, 900, 300, 30); + if(video_exists) + show_animation(mode, "rogueviz/nil/emty-ring.mp4", 720, 900, 300, 30); + else if(pic_exists) + show_picture(mode, "rogueviz/nil/emty-ring.png"); + else + slide_error(mode, "(image not available)"); no_other_hud(mode); } }, diff --git a/rogueviz/presentation.cpp b/rogueviz/presentation.cpp index 95eb02e3..66529aec 100644 --- a/rogueviz/presentation.cpp +++ b/rogueviz/presentation.cpp @@ -163,7 +163,10 @@ void read_all(int fd, void *buf, int cnt) { /* note: this loads the whole animation uncompressed into memory, so it is suitable only for short presentations */ void show_animation(presmode mode, string s, int sx, int sy, int frames, int fps) { #if CAP_VIDEO - if(mode == pmStartAll) { + if(mode == pmStartAll || mode == pmStart) { + /* load only once */ + if(textures.count(s + "@0")) return; + /* actually load */ array tab; if(pipe(&tab[0])) { addMessage(format("Error: %s", strerror(errno)));