Differences From Artifact [97ecb02030]:
- File src/world.m — part of check-in [e8f80b0482] at 2025-03-23 02:03:32 on branch trunk — Convert monster into a class (user: js, size: 10969) [annotate] [blame] [check-ins using]
To Artifact [9e368d7a28]:
- File
src/world.m
— part of check-in
[6b85eefc85]
at
2025-03-23 02:47:40
on branch trunk
— Remove loop[ijkl]
They confused clang-format a lot. (user: js, size: 11563) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
15 16 17 18 19 20 21 | // set all cubes with "tag" to space, if tag is 0 then reset ALL tagged cubes // according to type void settag(int tag, int type) { int maxx = 0, maxy = 0, minx = ssize, miny = ssize; | | < > | > | | | | | | | | | | | | | | | | | | | > | | | > > > | | > > > | > < > | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | // set all cubes with "tag" to space, if tag is 0 then reset ALL tagged cubes // according to type void settag(int tag, int type) { int maxx = 0, maxy = 0, minx = ssize, miny = ssize; for (int x = 0; x < ssize; x++) { for (int y = 0; y < ssize; y++) { struct sqr *s = S(x, y); if (s->tag) { if (tag) { if (tag == s->tag) s->type = SPACE; else continue; } else s->type = type ? SOLID : SPACE; if (x > maxx) maxx = x; if (y > maxy) maxy = y; if (x < minx) minx = x; if (y < miny) miny = y; } } } if (maxx) { // remip minimal area of changed geometry struct block b = { minx, miny, maxx - minx + 1, maxy - miny + 1 }; remip(&b, 0); } } // reset for editing or map saving void resettagareas() { settag(0, 0); } // set for playing void settagareas() { settag(0, 1); [ents enumerateObjectsUsingBlock:^(Entity *e, size_t i, bool *stop) { if (ents[i].type == CARROT) setspawn(i, true); }]; } void trigger(int tag, int type, bool savegame) { if (!tag) return; |
︙ | ︙ | |||
119 120 121 122 123 124 125 | o[1] = SWS(w, x + 1, y, ws); o[2] = SWS(w, x + 1, y + 1, ws); o[3] = SWS(w, x, y + 1, ws); // the target cube in the higher mip level struct sqr *r = SWS(v, x / 2, y / 2, vs); *r = *o[0]; uchar nums[MAXTYPE]; | > | > | > | > > | < | | | | | > | > | > | > | | | > | | > | | > | > | | | | | | > | | | | > | < | < | 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | o[1] = SWS(w, x + 1, y, ws); o[2] = SWS(w, x + 1, y + 1, ws); o[3] = SWS(w, x, y + 1, ws); // the target cube in the higher mip level struct sqr *r = SWS(v, x / 2, y / 2, vs); *r = *o[0]; uchar nums[MAXTYPE]; for (int i = 0; i < MAXTYPE; i++) nums[i] = 0; for (int j = 0; j < 4; j++) nums[o[j]->type]++; // cube contains both solid and space, treated // specially in the renderer r->type = SEMISOLID; for (int k = 0; k < MAXTYPE; k++) if (nums[k] == 4) r->type = k; if (!SOLID(r)) { int floor = 127, ceil = -128; for (int i = 0; i < 4; i++) { if (!SOLID(o[i])) { int fh = o[i]->floor; int ch = o[i]->ceil; if (r->type == SEMISOLID) { if (o[i]->type == FHF) // crap hack, // needed for // rendering // large mips // next to hfs fh -= o[i]->vdelta / 4 + 2; if (o[i]->type == CHF) // FIXME: needs // to somehow // take into // account // middle // vertices on // higher mips ch += o[i]->vdelta / 4 + 2; } if (fh < floor) // take lowest floor and // highest ceil, so we // never have to see // missing lower/upper // from the side floor = fh; if (ch > ceil) ceil = ch; } } r->floor = floor; r->ceil = ceil; } if (r->type == CORNER) // special case: don't ever split even if // textures etc are different goto mip; r->defer = 1; if (SOLID(r)) { for (int i = 0; i < 3; i++) { if (o[i]->wtex != o[3]->wtex) // on an all solid cube, only // thing that needs to be equal // for a perfect mip is the // wall texture goto c; } } else { for (int i = 0; i < 3; i++) { // perfect mip even if light is not // exactly equal if (o[i]->type != o[3]->type || o[i]->floor != o[3]->floor || o[i]->ceil != o[3]->ceil || o[i]->ftex != o[3]->ftex || o[i]->ctex != o[3]->ctex || |
︙ | ︙ | |||
224 225 226 227 228 229 230 | ->vdelta) goto c; } } { // if any of the constituents is not perfect, // then this one isn't either | > | > | 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | ->vdelta) goto c; } } { // if any of the constituents is not perfect, // then this one isn't either for (int i = 0; i < 4; i++) if (o[i]->defer) goto c; } mip: r->defer = 0; c:; } s.x /= 2; s.y /= 2; |
︙ | ︙ | |||
318 319 320 321 322 323 324 | if (t == LIGHT) calclight(); } int findtype(OFString *what) { | > | > | 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | if (t == LIGHT) calclight(); } int findtype(OFString *what) { for (int i = 0; i < MAXENTTYPES; i++) if ([what isEqual:entnames[i]]) return i; conoutf(@"unknown entity type \"%@\"", what); return NOTUSED; } Entity * newentity(int x, int y, int z, OFString *what, int v1, int v2, int v3, int v4) { |
︙ | ︙ | |||
424 425 426 427 428 429 430 | int findentity(int type, int index) { for (int i = index; i < ents.count; i++) if (ents[i].type == type) return i; | > | > | < | 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | int findentity(int type, int index) { for (int i = index; i < ents.count; i++) if (ents[i].type == type) return i; for (int j = 0; j < index; j++) if (ents[j].type == type) return j; return -1; } struct sqr *wmip[LARGEST_FACTOR * 2]; void setupworld(int factor) { ssize = 1 << (sfactor = factor); cubicsize = ssize * ssize; mipsize = cubicsize * 134 / 100; struct sqr *w = world = OFAllocZeroedMemory(mipsize, sizeof(struct sqr)); for (int i = 0; i < LARGEST_FACTOR * 2; i++) { wmip[i] = w; w += cubicsize >> (i * 2); } } // main empty world creation routine, if passed factor -1 will enlarge old // world by 1 |
︙ | ︙ | |||
466 467 468 469 470 471 472 | } if (factor < SMALLEST_FACTOR) factor = SMALLEST_FACTOR; if (factor > LARGEST_FACTOR) factor = LARGEST_FACTOR; setupworld(factor); | | < > | | | | | | | | | | > | < > | | > > | > > | | 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | } if (factor < SMALLEST_FACTOR) factor = SMALLEST_FACTOR; if (factor > LARGEST_FACTOR) factor = LARGEST_FACTOR; setupworld(factor); for (int x = 0; x < ssize; x++) { for (int y = 0; y < ssize; y++) { struct sqr *s = S(x, y); s->r = s->g = s->b = 150; s->ftex = DEFAULT_FLOOR; s->ctex = DEFAULT_CEIL; s->wtex = s->utex = DEFAULT_WALL; s->type = SOLID; s->floor = 0; s->ceil = 16; s->vdelta = 0; s->defer = 0; } } strncpy(hdr.head, "CUBE", 4); hdr.version = MAPVERSION; hdr.headersize = sizeof(struct header); hdr.sfactor = sfactor; if (copy) { for (int x = 0; x < ssize / 2; x++) { for (int y = 0; y < ssize / 2; y++) { *S(x + ssize / 4, y + ssize / 4) = *SWS(oldworld, x, y, ssize / 2); } } for (Entity *e in ents) { e.x += ssize / 4; e.y += ssize / 4; } } else { char buffer[128] = "Untitled Map by Unknown"; memcpy(hdr.maptitle, buffer, 128); hdr.waterlevel = -100000; for (int i = 0; i < 15; i++) hdr.reserved[i] = 0; for (int k = 0; k < 3; k++) for (int i = 0; i < 256; i++) hdr.texlists[k][i] = i; [ents removeAllObjects]; struct block b = { 8, 8, ssize - 16, ssize - 16 }; edittypexy(SPACE, &b); } calclight(); startmap(@"base/unnamed"); |
︙ | ︙ |