track missing models without "nomodel"-crutch
* missing models now have their own list "mdlnotfound". * also added a few comments (looks silly, though)
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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();
|
||||
|
||||
+17
-22
@@ -109,56 +109,51 @@ COMMAND(mapmodel, "iiiss");
|
||||
COMMAND(mapmodelreset, "");
|
||||
|
||||
hashtable<const char *, model *> mdllookup;
|
||||
model *nomodel = NULL;
|
||||
hashtable<const char *, char> 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user