1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
|
// world.cpp: core map management stuff
#include "cube.h"
#import "DynamicEntity.h"
#import "Entity.h"
extern OFString *entnames[]; // lookup from map entities above to strings
sqr *world = NULL;
int sfactor, ssize, cubicsize, mipsize;
header hdr;
// 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;
loop(x, ssize) loop(y, ssize)
{
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;
}
}
block b = { minx, miny, maxx - minx + 1, maxy - miny + 1 };
if (maxx)
remip(&b, 0); // remip minimal area of changed geometry
}
void
resettagareas()
{
|
|
|
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
|
// world.cpp: core map management stuff
#include "cube.h"
#import "DynamicEntity.h"
#import "Entity.h"
extern OFString *entnames[]; // lookup from map entities above to strings
struct sqr *world = NULL;
int sfactor, ssize, cubicsize, mipsize;
struct header hdr;
// 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;
loop(x, ssize) loop(y, ssize)
{
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;
}
}
struct block b = { minx, miny, maxx - minx + 1, maxy - miny + 1 };
if (maxx)
remip(&b, 0); // remip minimal area of changed geometry
}
void
resettagareas()
{
|
︙ | | | ︙ | |
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
// main geometric mipmapping routine, recursively rebuild mipmaps within block
// b. tries to produce cube out of 4 lower level mips as well as possible, sets
// defer to 0 if mipped cube is a perfect mip, i.e. can be rendered at this mip
// level indistinguishable from its constituent cubes (saves considerable
// rendering time if this is possible).
void
remip(const block *b, int level)
{
if (level >= SMALLEST_FACTOR)
return;
int lighterr = getvar(@"lighterror") * 3;
sqr *w = wmip[level];
sqr *v = wmip[level + 1];
int ws = ssize >> level;
int vs = ssize >> (level + 1);
block s = *b;
if (s.x & 1) {
s.x--;
s.xs++;
}
if (s.y & 1) {
s.y--;
s.ys++;
}
s.xs = (s.xs + 1) & ~1;
s.ys = (s.ys + 1) & ~1;
for (int x = s.x; x < s.x + s.xs; x += 2)
for (int y = s.y; y < s.y + s.ys; y += 2) {
sqr *o[4];
o[0] = SWS(w, x, y, ws); // the 4 constituent cubes
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
sqr *r = SWS(v, x / 2, y / 2, vs);
*r = *o[0];
uchar nums[MAXTYPE];
loopi(MAXTYPE) nums[i] = 0;
loopj(4) nums[o[j]->type]++;
// cube contains both solid and space, treated
// specially in the renderer
r->type = SEMISOLID;
|
|
|
|
|
|
|
|
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
// main geometric mipmapping routine, recursively rebuild mipmaps within block
// b. tries to produce cube out of 4 lower level mips as well as possible, sets
// defer to 0 if mipped cube is a perfect mip, i.e. can be rendered at this mip
// level indistinguishable from its constituent cubes (saves considerable
// rendering time if this is possible).
void
remip(const struct block *b, int level)
{
if (level >= SMALLEST_FACTOR)
return;
int lighterr = getvar(@"lighterror") * 3;
struct sqr *w = wmip[level];
struct sqr *v = wmip[level + 1];
int ws = ssize >> level;
int vs = ssize >> (level + 1);
struct block s = *b;
if (s.x & 1) {
s.x--;
s.xs++;
}
if (s.y & 1) {
s.y--;
s.ys++;
}
s.xs = (s.xs + 1) & ~1;
s.ys = (s.ys + 1) & ~1;
for (int x = s.x; x < s.x + s.xs; x += 2)
for (int y = s.y; y < s.y + s.ys; y += 2) {
struct sqr *o[4];
o[0] = SWS(w, x, y, ws); // the 4 constituent cubes
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];
loopi(MAXTYPE) nums[i] = 0;
loopj(4) nums[o[j]->type]++;
// cube contains both solid and space, treated
// specially in the renderer
r->type = SEMISOLID;
|
︙ | | | ︙ | |
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
s.y /= 2;
s.xs /= 2;
s.ys /= 2;
remip(&s, level + 1);
}
void
remipmore(const block *b, int level)
{
block bb = *b;
if (bb.x > 1)
bb.x--;
if (bb.y > 1)
bb.y--;
if (bb.xs < ssize - 3)
bb.xs++;
|
|
|
|
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
s.y /= 2;
s.xs /= 2;
s.ys /= 2;
remip(&s, level + 1);
}
void
remipmore(const struct block *b, int level)
{
struct block bb = *b;
if (bb.x > 1)
bb.x--;
if (bb.y > 1)
bb.y--;
if (bb.xs < ssize - 3)
bb.xs++;
|
︙ | | | ︙ | |
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
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
480
481
482
483
484
485
486
487
488
489
490
491
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
|
for (int i = index; i < ents.count; i++)
if (ents[i].type == type)
return i;
loopj(index) if (ents[j].type == type) return j;
return -1;
}
sqr *wmip[LARGEST_FACTOR * 2];
void
setupworld(int factor)
{
ssize = 1 << (sfactor = factor);
cubicsize = ssize * ssize;
mipsize = cubicsize * 134 / 100;
sqr *w = world = (sqr *)OFAllocZeroedMemory(mipsize, sizeof(sqr));
loopi(LARGEST_FACTOR * 2)
{
wmip[i] = w;
w += cubicsize >> (i * 2);
}
}
// main empty world creation routine, if passed factor -1 will enlarge old
// world by 1
void
empty_world(int factor, bool force)
{
if (!force && noteditmode())
return;
cleardlights();
pruneundos(0);
sqr *oldworld = world;
bool copy = false;
if (oldworld && factor < 0) {
factor = sfactor + 1;
copy = true;
}
if (factor < SMALLEST_FACTOR)
factor = SMALLEST_FACTOR;
if (factor > LARGEST_FACTOR)
factor = LARGEST_FACTOR;
setupworld(factor);
loop(x, ssize) loop(y, ssize)
{
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(header);
hdr.sfactor = sfactor;
if (copy) {
loop(x, ssize / 2) loop(y, ssize / 2)
{
*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;
loopi(15) hdr.reserved[i] = 0;
loopk(3) loopi(256) hdr.texlists[k][i] = i;
[ents removeAllObjects];
block b = { 8, 8, ssize - 16, ssize - 16 };
edittypexy(SPACE, &b);
}
calclight();
startmap(@"base/unnamed");
if (oldworld) {
OFFreeMemory(oldworld);
|
|
>
|
|
|
|
|
|
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
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
480
481
482
483
484
485
486
487
488
489
490
491
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
|
for (int i = index; i < ents.count; i++)
if (ents[i].type == type)
return i;
loopj(index) 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));
loopi(LARGEST_FACTOR * 2)
{
wmip[i] = w;
w += cubicsize >> (i * 2);
}
}
// main empty world creation routine, if passed factor -1 will enlarge old
// world by 1
void
empty_world(int factor, bool force)
{
if (!force && noteditmode())
return;
cleardlights();
pruneundos(0);
struct sqr *oldworld = world;
bool copy = false;
if (oldworld && factor < 0) {
factor = sfactor + 1;
copy = true;
}
if (factor < SMALLEST_FACTOR)
factor = SMALLEST_FACTOR;
if (factor > LARGEST_FACTOR)
factor = LARGEST_FACTOR;
setupworld(factor);
loop(x, ssize) loop(y, ssize)
{
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) {
loop(x, ssize / 2) loop(y, ssize / 2)
{
*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;
loopi(15) hdr.reserved[i] = 0;
loopk(3) loopi(256) hdr.texlists[k][i] = i;
[ents removeAllObjects];
struct block b = { 8, 8, ssize - 16, ssize - 16 };
edittypexy(SPACE, &b);
}
calclight();
startmap(@"base/unnamed");
if (oldworld) {
OFFreeMemory(oldworld);
|
︙ | | | ︙ | |