MCPcopy Create free account
hub / github.com/assaultcube/AC / sorttextureslots

Function sorttextureslots

source/src/texture.cpp:1194–1313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1192}
1193
1194void sorttextureslots(char **args, int numargs)
1195{
1196 bool nomerge = false, mergeused = false, nosort = false, unknownarg = false;
1197 vector<int> presort;
1198 presort.add(0); // skymap needs to stay on #0
1199 loopi(numargs) if(args[i][0])
1200 {
1201 if(!strcasecmp(args[i], "nomerge")) nomerge = true;
1202 else if(!strcasecmp(args[i], "nosort")) nosort = true;
1203 else if(!strcasecmp(args[i], "mergeused")) mergeused = true;
1204 else if(isdigit(args[i][0])) presort.add(ATOI(args[i]));
1205 else { conoutf("sorttextureslots: unknown argument \"%s\"", args[i]); unknownarg = true; }
1206 }
1207 while(presort.length() < 5) presort.add(presort.length());
1208
1209 EDITMP("sorttextureslots");
1210 if(unknownarg || slots.length() < 5) return;
1211
1212 int used[256] = { 0 };
1213 textureslotusagemapmodels(used);
1214 textureslotusagegeometry(used);
1215
1216 vector<temptexslot> tempslots;
1217 loopv(slots)
1218 {
1219 tempslots.add().s = slots[i];
1220 tempslots.last().oldslot.add(i);
1221 tempslots.last().used = used[i] > 0;
1222 }
1223 tempslots.sort(tempslotsort);
1224
1225 // remove double entries (if requested)
1226 if(!nomerge) loopvrev(tempslots) if(i > 0)
1227 {
1228 temptexslot &s1 = tempslots[i], &s0 = tempslots[i - 1];
1229 if(s1.oldslot[0] > 4 && s0.oldslot[0] > 0 && !strcmp(s0.s.name, s1.s.name) && s0.s.scale == s1.s.scale && (mergeused || !s0.used || !s1.used))
1230 {
1231 if(s1.used) s0.used = true;
1232 loopvj(s1.oldslot) s0.oldslot.add(s1.oldslot[j]);
1233 tempslots.remove(i);
1234 }
1235 }
1236
1237 // sort special textures (like skymap) back front - also, revert sorting, if it's unwanted
1238 if(nosort) tempslots.sort(tempslotunsort);
1239 loopv(presort) for(int n = i + 1; n < presort.length(); n++) if(presort[i] == presort[n]) presort.remove(n); // first occurrence is kept
1240 loopvk(presort)
1241 {
1242 loopv(tempslots)
1243 {
1244 bool yep = false;
1245 loopvj(tempslots[i].oldslot) if(tempslots[i].oldslot[j] == presort[k]) yep = true;
1246 if(yep && i > k)
1247 {
1248 temptexslot t = tempslots.remove(i);
1249 tempslots.insert(k, t);
1250 break;
1251 }

Callers

nothing calls this directly

Calls 14

textureslotusagegeometryFunction · 0.85
remipFunction · 0.85
sortMethod · 0.80
shrinkMethod · 0.80
loopiFunction · 0.70
conoutfFunction · 0.70
loopvrevFunction · 0.70
loopvjFunction · 0.70
loopvFunction · 0.70
loopkFunction · 0.70
addMethod · 0.45

Tested by

no test coverage detected