From 6cd5be62252919e65652e8847788f41ecf4f1dad Mon Sep 17 00:00:00 2001 From: ac-stef Date: Thu, 1 Sep 2016 22:48:11 +0200 Subject: [PATCH] show how many uses of a texture slot are actually visible The command textureslotusagelist now returns two values per slot: usage and visibility. If given the argument "onlymostvisible", instead of the regular list, a list of only the most used wall, floor, ceiling and upper wall textures (alternating with the keywords) is returned. Example: echo (textureslotusagelist onlymostvisible) --> wall 211 floor 45 ceiling 0 "upper wall" 79 DOCREF textureslotusagelist --- config/menus_edit.cfg | 6 +++--- source/src/texture.cpp | 47 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/config/menus_edit.cfg b/config/menus_edit.cfg index c2c20951..5a35e37a 100644 --- a/config/menus_edit.cfg +++ b/config/menus_edit.cfg @@ -263,11 +263,11 @@ menuinit [ push ecurmenu (escape (curmenu)) push i 0 push info "" - looplist (textureslotusagelist) cnt [ + looplist (textureslotusagelist) [cnt used] [ info = (edittextureslot $i) if (|| $cnt (strlen $info)) [ if (! (strlen $info)) [ info = " \fs\f3\fr" ] - menuitem (concatword "edit texture slot #" $i ": " $info " (" $cnt " uses)") (concat alias __texslot $i "; showmenu [Edit texture slot]") (concat chmenutexture $ecurmenu (at $info 1)) + menuitem (concatword "edit texture slot #" $i ": " $info " (" $cnt " uses, " $used " visible)") (concat __texslot = $i "; showmenu [Edit texture slot]") (concat chmenutexture $ecurmenu (at $info 1)) ] += i 1 ] @@ -342,7 +342,7 @@ menuinit [ __tex_togo = (at $slots 0) __tex_joined = (at $slots $last) looplist $slots ii [ - menuitem (concatword " #" $ii ": " (edittextureslot $ii) " (" (at $usemap $ii) " uses)") (concat alias __texslot $ii "; showmenu [Edit texture slot]") + menuitem (concatword " #" $ii ": " (edittextureslot $ii) " (" (at $usemap (* $ii 2)) " uses, " (at $usemap (+ (* $ii 2) 1)) " visible)") (concat alias __texslot $ii "; showmenu [Edit texture slot]") ] menuitem "" -1 menuitem "Merge" -1 diff --git a/source/src/texture.cpp b/source/src/texture.cpp index b4e5cbf4..308414cc 100644 --- a/source/src/texture.cpp +++ b/source/src/texture.cpp @@ -980,9 +980,12 @@ void textureslotusagemapmodels(int *used) used[0] = old0; } -void textureslotusagegeometry(int *used) +void textureslotusagegeometry(int *used, int *visible = NULL, int *mostvisible = NULL) { sqr *s = world; + int *mostw = mostvisible ? new int[1024] : NULL, *mostc = mostvisible ? mostw + 256 : NULL, *mostf = mostvisible ? mostw + 512 : NULL, *mostu = mostvisible ? mostw + 768 : NULL; + if(mostvisible) loopi(1024) mostw[i] = 0; + if(visible) calcworldvisibility(); loopirev(cubicsize) { used[s->wtex]++; @@ -992,23 +995,59 @@ void textureslotusagegeometry(int *used) used[s->ftex]++; used[s->utex]++; } + if(visible && !(s->visible & INVISIBLE)) + { // cube not invisible + if(!(s->visible & INVISWTEX)) + { // lower wall visible + visible[s->wtex]++; + if(mostw) mostw[s->wtex]++; + } + if(s->type != SOLID) + { + if(!(s->visible & INVISUTEX)) + { // upper wall visible + visible[s->utex]++; + if(mostu) mostu[s->utex]++; + } + visible[s->ctex]++; + if(mostc) mostc[s->ctex]++; + visible[s->ftex]++; + if(mostf) mostf[s->ftex]++; + } + } s++; } + if(visible) clearworldvisibility(); + if(mostvisible) loopk(4) + { // find most visible texures (for all four geometry uses) + int *mx[4] = { mostw, mostf, mostc, mostu }, *m = mx[k], maxval = 0; + mostvisible[k] = -1; + loopi(256) if(m[i] > maxval) + { + maxval = m[i]; + mostvisible[k] = i; + } + } + if(mostw) delete[] mostw; } void textureslotusagelist(char *what) { - int used[256] = { 0 }; + int used[256] = { 0 }, visible[256]; + int mostvisible[4] = { 0 }; + bool onlymostvisible = !strcmp(what, "onlymostvisible"); if(strcmp(what, "onlygeometry")) { // if not only geometry, count map model usage textureslotusagemapmodels(used); } + loopi(256) visible[i] = used[i]; // all mapmodel uses count as "visible" as well if(strcmp(what, "onlymodels")) { // if not only models, count map geometry - textureslotusagegeometry(used); + textureslotusagegeometry(used, visible, onlymostvisible ? mostvisible : NULL); } vector res; - loopi(256) cvecprintf(res, "%d ", used[i]); + if(onlymostvisible) cvecprintf(res, "wall %d floor %d ceiling %d \"upper wall\" %d ", mostvisible[0], mostvisible[1], mostvisible[2], mostvisible[3]); + else loopi(256) cvecprintf(res, "%d %d ", used[i], visible[i]); res.last() = '\0'; result(res.getbuf()); }