From 7a7a8da3106a0fbad53390c8c0f4e3bd8f2720dc Mon Sep 17 00:00:00 2001 From: ac-stef Date: Wed, 3 Jun 2015 20:50:08 +0200 Subject: [PATCH] experimental: add per-slot mapmodel scale factors 4th parameter of the "mapmodel" command is now a scale factor between 0.25 and 4.0. Values outside that range (like the dummy zero from old map config files) are interpreted as 1.0 Scaling does not affect the clipping, which has to be adjusted manually. DOCREF mapmodel editmapmodelslot --- source/src/entities.cpp | 2 +- source/src/model.h | 2 +- source/src/rendermodel.cpp | 18 ++++++++++++------ source/src/worldio.cpp | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/source/src/entities.cpp b/source/src/entities.cpp index 965432b2..16a0934b 100644 --- a/source/src/entities.cpp +++ b/source/src/entities.cpp @@ -78,7 +78,7 @@ void rendermapmodels() { mapmodelinfo &mmi = getmminfo(e.attr2); if(!&mmi) continue; - rendermodel(mmi.name, ANIM_MAPMODEL|ANIM_LOOP, e.attr4, 0, vec(e.x, e.y, S(e.x, e.y)->floor + mmi.zoff + float(e.attr3) / ENTSCALE5), e.attr6, float(e.attr1) / ENTSCALE10, float(e.attr5) / ENTSCALE10, 10.0f); + rendermodel(mmi.name, ANIM_MAPMODEL|ANIM_LOOP, e.attr4, 0, vec(e.x, e.y, S(e.x, e.y)->floor + mmi.zoff + float(e.attr3) / ENTSCALE5), e.attr6, float(e.attr1) / ENTSCALE10, float(e.attr5) / ENTSCALE10, 10.0f, 0, NULL, NULL, mmi.scale); } } } diff --git a/source/src/model.h b/source/src/model.h index f0d9e91d..aac10f17 100644 --- a/source/src/model.h +++ b/source/src/model.h @@ -67,7 +67,7 @@ struct model virtual void endrender() {} }; -struct mapmodelinfo { int rad, h, zoff; string name; model *m; }; +struct mapmodelinfo { int rad, h, zoff; float scale; string name; model *m; }; enum { MMA_KEYWORDS = 0, MMA_DESC, MMA_DEFAULTPARAMS, MMA_USAGE, MMA_AUTHOR, MMA_LICENSE, MMA_DISTRIBUTION, MMA_VERSION, MMA_NUM }; diff --git a/source/src/rendermodel.cpp b/source/src/rendermodel.cpp index 8f57687b..e87b05f9 100644 --- a/source/src/rendermodel.cpp +++ b/source/src/rendermodel.cpp @@ -109,16 +109,19 @@ vector mapmodels; const char *mmpath = "mapmodels/"; const char *mmshortname(const char *name) { return !strncmp(name, mmpath, strlen(mmpath)) ? name + strlen(mmpath) : name; } -void mapmodel(int *rad, int *h, int *zoff, char *snap, char *name) +void mapmodel(int *rad, int *h, int *zoff, char *scale, char *name) { - if(*snap && *name) // ignore "mapmodel" commands with insufficient parameters + if(*scale && *name) // ignore "mapmodel" commands with insufficient parameters { intret(mapmodels.length()); mapmodelinfo &mmi = mapmodels.add(); mmi.rad = *rad; mmi.h = *h; mmi.zoff = *zoff; + mmi.scale = atof(scale); + if(mmi.scale < 0.25f || mmi.scale > 4.0f) mmi.scale = 1.0f; mmi.m = NULL; + filtertext(name, name, FTXT__MEDIAFILEPATH); formatstring(mmi.name)("%s%s", mmpath, name); mapmodelchanged = 1; @@ -182,24 +185,27 @@ void deletemapmodelslot(int *n, char *opt) // delete mapmodel slot - only if unu } COMMAND(deletemapmodelslot, "is"); -void editmapmodelslot(int *n, char *rad, char *h, char *zoff, char *snap, char *name) // edit slot parameters != "" +void editmapmodelslot(int *n, char *rad, char *h, char *zoff, char *scale, char *name) // edit slot parameters != "" { string res = ""; if(!noteditmode("editmapmodelslot") && !multiplayer(true) && mapmodels.inrange(*n)) { mapmodelinfo &mmi = mapmodels[*n]; - if(*rad || *h || *zoff || *snap || *name) + if(*rad || *h || *zoff || *scale || *name) { // change attributes if(*rad) mmi.rad = strtol(rad, NULL, 0); if(*h) mmi.h = strtol(h, NULL, 0); if(*zoff) mmi.zoff = strtol(zoff, NULL, 0); + float s = atof(scale); + if(s < 0.25f || s > 4.0f) s = 1.0f; + if(*scale) mmi.scale = s; mmi.m = NULL; if(*name) formatstring(mmi.name)("%s%s", mmpath, name); unsavededits++; mapmodelchanged = 1; hdr.flags |= MHF_AUTOMAPCONFIG; // requires automapcfg } - formatstring(res)("%d %d %d 0 \"%s\"", mmi.rad, mmi.h, mmi.zoff, mmshortname(mmi.name)); // give back all current attributes + formatstring(res)("%d %d %d %s \"%s\"", mmi.rad, mmi.h, mmi.zoff, floatstr(mmi.scale, true), mmshortname(mmi.name)); // give back all current attributes } result(res); } @@ -606,7 +612,7 @@ void rendermodel(const char *mdl, int anim, int tex, float rad, const vec &o, fl if(rad >= 0) { - if(!rad) rad = m->radius; + if(!rad) rad = m->radius * scale; if(isoccluded(camera1->o.x, camera1->o.y, o.x-rad, o.y-rad, rad*2)) return; } diff --git a/source/src/worldio.cpp b/source/src/worldio.cpp index 1b37041d..fea3c2c3 100644 --- a/source/src/worldio.cpp +++ b/source/src/worldio.cpp @@ -427,7 +427,7 @@ void getcurrentmapconfig(vector &f, bool onlysounds) { mapmodelinfo &mmi = getmminfo(i); if(!&mmi) break; - cvecprintf(f, "mapmodel %d %d %d 0 \"%s\"\n", mmi.rad, mmi.h, mmi.zoff, mmshortname(mmi.name)); + cvecprintf(f, "mapmodel %d %d %d %s \"%s\"\n", mmi.rad, mmi.h, mmi.zoff, mmi.scale == 1.0f ? "0" : floatstr(mmi.scale, true), mmshortname(mmi.name)); } cvecprintf(f, "\ntexturereset\n"); loopi(256)