From 2a6b8fb234a10f2af1a55fe3228154934edaf663 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Wed, 26 Nov 2014 21:23:59 +0100 Subject: [PATCH] track missing models without "nomodel"-crutch * missing models now have their own list "mdlnotfound". * also added a few comments (looks silly, though) --- source/src/main.cpp | 3 --- source/src/protos.h | 1 - source/src/rendermodel.cpp | 39 +++++++++++++++++--------------------- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/source/src/main.cpp b/source/src/main.cpp index 06ee2e35..9933f943 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -1160,9 +1160,6 @@ int main(int argc, char **argv) notexture = noworldtexture = textureload("packages/misc/notexture.jpg"); if(!notexture) fatal("could not find core textures (hint: run AssaultCube from the parent of the bin directory)"); - nomodel = loadmodel("misc/gib01", -1); //FIXME: need actual placeholder model - if(!notexture) fatal("could not find core models"); - initlog("console"); per_idents = false; // Main font file, all other font files execute from here. diff --git a/source/src/protos.h b/source/src/protos.h index d5f6e494..1c07fad0 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -739,7 +739,6 @@ extern void clearmodelbatches(); extern mapmodelinfo &getmminfo(int i); extern int findanim(const char *name); extern void loadskin(const char *dir, const char *altdir, Texture *&skin); -extern model *nomodel; extern model *loadmodel(const char *name, int i = -1, bool trydl = false); extern void preload_playermodels(); extern void preload_entmodels(); diff --git a/source/src/rendermodel.cpp b/source/src/rendermodel.cpp index dc9697b5..a74f7004 100644 --- a/source/src/rendermodel.cpp +++ b/source/src/rendermodel.cpp @@ -109,56 +109,51 @@ COMMAND(mapmodel, "iiiss"); COMMAND(mapmodelreset, ""); hashtable mdllookup; -model *nomodel = NULL; +hashtable mdlnotfound; -model *loadmodel(const char *name, int i, bool trydl) +model *loadmodel(const char *name, int i, bool trydl) // load model by name (optional) or from mapmodels[i] { - if(!name) + if(!name) // name == NULL -> get index i from mapmodels[] { if(!mapmodels.inrange(i)) return NULL; mapmodelinfo &mmi = mapmodels[i]; - if(mmi.m) return mmi.m; + if(mmi.m) return mmi.m; // mapmodels[i] was already loaded name = mmi.name; } + if(mdlnotfound.access(name)) return NULL; // already tried to find that earlier -> not available model **mm = mdllookup.access(name); model *m; - if(mm) m = *mm; + if(mm) m = *mm; // a model of that name is already loaded else { pushscontext(IEXC_MDLCFG); - m = new md2(name); + m = new md2(name); // try md2 loadingmodel = m; - if(!m->load()) + if(!m->load()) // md2 didn't load { delete m; - m = new md3(name); + m = new md3(name); // try md3 loadingmodel = m; - if(!m->load()) + if(!m->load()) // md3 didn't load -> we don't have that model { delete m; - loadingmodel = NULL; + m = loadingmodel = NULL; if(trydl) { defformatstring(dl)("packages/models/%s", name); requirepackage(PCK_MAPMODEL, dl); } + else + { + conoutf("\f3failed to load model %s", name); + mdlnotfound.access(newstring(name), 0); // do not search for this name again + } } } popscontext(); - if(!loadingmodel) - { - if(!trydl) - { - conoutf("\f3failed to load model %s", name); - if(!nomodel) nomodel = new md2("nomodel"); - m = nomodel; - mdllookup.access(newstring(name), m); - } - } - else mdllookup.access(m->name(), m); + if(loadingmodel && m) mdllookup.access(m->name(), m); loadingmodel = NULL; } - if(m == nomodel) return NULL; if(mapmodels.inrange(i) && !mapmodels[i].m) mapmodels[i].m = m; return m; }