automatic mapmodel menus

auto-generate mapmodel menus depending on the actually available models
in the current map config.

Also fixes memory leak in "newmenu".

DOCREF mapmodelname mapmodelbyname mapmodelchanged
This commit is contained in:
ac-stef
2015-04-12 18:09:36 +02:00
parent f511889731
commit 57a0d286c1
3 changed files with 309 additions and 280 deletions
+12
View File
@@ -86,6 +86,8 @@ void mdlcachelimit(int *limit)
COMMAND(mdlcachelimit, "i");
VAR(mapmodelchanged, 0, 0, 1);
vector<mapmodelinfo> mapmodels;
void mapmodel(int *rad, int *h, int *zoff, char *snap, char *name)
@@ -96,11 +98,13 @@ void mapmodel(int *rad, int *h, int *zoff, char *snap, char *name)
mmi.zoff = *zoff;
mmi.m = NULL;
formatstring(mmi.name)("mapmodels/%s", name);
mapmodelchanged = 1;
}
void mapmodelreset()
{
if(execcontext==IEXC_MAPCFG) mapmodels.shrink(0);
mapmodelchanged = 1;
}
mapmodelinfo &getmminfo(int i) { return mapmodels.inrange(i) ? mapmodels[i] : *(mapmodelinfo *)0; }
@@ -108,6 +112,14 @@ mapmodelinfo &getmminfo(int i) { return mapmodels.inrange(i) ? mapmodels[i] : *(
COMMAND(mapmodel, "iiiss");
COMMAND(mapmodelreset, "");
COMMANDF(mapmodelname, "i", (int *idx) { result(mapmodels.inrange(*idx) ? mapmodels[*idx].name : ""); });
COMMANDF(mapmodelbyname, "s", (char *name)
{
string res = "";
loopv(mapmodels) if(!strcmp(name, mapmodels[i].name)) concatformatstring(res, "%s%d", *res ? " " : "", i);
result(res);
});
hashtable<const char *, model *> mdllookup;
hashtable<const char *, char> mdlnotfound;