MCPcopy Index your code
hub / github.com/assaultcube/AC / sortmapmodelslots

Function sortmapmodelslots

source/src/rendermodel.cpp:247–311  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

245}
246
247void sortmapmodelslots(char **args, int numargs)
248{
249 bool nomerge = false, mergeused = false, nosort = false, unknownarg = false;
250 loopi(numargs) if(args[i][0])
251 {
252 if(!strcasecmp(args[i], "nomerge")) nomerge = true;
253 else if(!strcasecmp(args[i], "nosort")) nosort = true;
254 else if(!strcasecmp(args[i], "mergeused")) mergeused = true;
255 else { conoutf("sortmapmodelslots: unknown argument \"%s\"", args[i]); unknownarg = true; }
256 }
257
258 EDITMP("sortmapmodelslots");
259 if(unknownarg || mapmodels.length() < 3) return;
260
261 vector<tempmmslot> tempslots;
262 loopv(mapmodels)
263 {
264 tempslots.add().m = mapmodels[i];
265 tempslots.last().oldslot.add(i);
266 tempslots.last().used = false;
267 }
268 loopv(ents) if(ents[i].type == MAPMODEL && tempslots.inrange(ents[i].attr2)) tempslots[ents[i].attr2].used = true;
269 tempslots.sort(tempmmsort);
270
271 // remove double entries
272 if(!nomerge) loopvrev(tempslots) if(i > 0)
273 {
274 tempmmslot &s1 = tempslots[i], &s0 = tempslots[i - 1];
275 if(!tempmmcmp(&s0, &s1) && (mergeused || !s0.used || !s1.used))
276 {
277 if(s1.used) s0.used = true;
278 loopvj(s1.oldslot) s0.oldslot.add(s1.oldslot[j]);
279 tempslots.remove(i);
280 }
281 }
282 if(nosort) tempslots.sort(tempmmunsort);
283
284 // create translation table
285 uchar newslot[256];
286 loopk(256) newslot[k] = k;
287 loopv(tempslots)
288 {
289 tempmmslot &t = tempslots[i];
290 loopvj(t.oldslot)
291 {
292 if(t.oldslot[j] < 256) newslot[t.oldslot[j]] = i;
293 }
294 }
295
296 // translate all mapmodel entities
297 loopv(ents) if(ents[i].type == MAPMODEL) ents[i].attr2 = newslot[ents[i].attr2];
298
299 conoutf("%d mapmodel slots%s, %d %sslots merged", tempslots.length(), nosort ? "" : " sorted", mapmodels.length() - tempslots.length(), mergeused ? "" : "unused ");
300
301 // rewrite mapmodel slot list
302 mapmodels.shrink(tempslots.length());
303 loopv(tempslots)
304 {

Callers

nothing calls this directly

Calls 13

tempmmcmpFunction · 0.85
inrangeMethod · 0.80
sortMethod · 0.80
shrinkMethod · 0.80
loopiFunction · 0.70
conoutfFunction · 0.70
loopvFunction · 0.70
loopvrevFunction · 0.70
loopvjFunction · 0.70
loopkFunction · 0.70
lengthMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected