38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
minx = x;
if (y < miny)
miny = y;
}
}
block b = { minx, miny, maxx - minx + 1, maxy - miny + 1 };
if (maxx)
remip(b); // remip minimal area of changed geometry
}
void
resettagareas()
{
settag(0, 0);
} // reset for editing or map saving
|
|
|
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
minx = x;
if (y < miny)
miny = y;
}
}
block b = { minx, miny, maxx - minx + 1, maxy - miny + 1 };
if (maxx)
remip(&b); // remip minimal area of changed geometry
}
void
resettagareas()
{
settag(0, 0);
} // reset for editing or map saving
|
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
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
212
|
// 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(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);
sqr *r = SWS(v, x / 2, y / 2,
vs); // the target cube in the higher mip level
*r = *o[0];
uchar nums[MAXTYPE];
loopi(MAXTYPE) nums[i] = 0;
loopj(4) nums[o[j]->type]++;
r->type =
SEMISOLID; // cube contains both solid and space,
// treated specially in the renderer
loopk(MAXTYPE) if (nums[k] == 4) r->type = k;
if (!SOLID(r)) {
int floor = 127, ceil = -128, num = 0;
loopi(4) if (!SOLID(o[i]))
{
num++;
int fh = o[i]->floor;
int ch = o[i]->ceil;
if (r->type == SEMISOLID) {
if (o[i]->type == FHF)
fh -= o[i]->vdelta / 4 +
2; // crap hack,
// needed for
// rendering
// large mips
// next to hfs
if (o[i]->type == CHF)
ch += o[i]->vdelta / 4 +
2; // FIXME: needs
// to somehow
// take into
// account middle
// vertices on
// higher mips
}
if (fh < floor)
floor =
fh; // take lowest floor and
// highest ceil, so we
// never have to see
// missing lower/upper
// from the side
if (ch > ceil)
ceil = ch;
}
r->floor = floor;
r->ceil = ceil;
}
if (r->type == CORNER)
goto mip; // special case: don't ever split even
// if textures etc are different
r->defer = 1;
if (SOLID(r)) {
loopi(3)
{
if (o[i]->wtex != o[3]->wtex)
goto c; // on an all solid cube,
// only thing that needs
// to be equal for a
// perfect mip is the
// wall texture
}
} else {
loopi(3)
{
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 ||
abs(o[i + 1]->r - o[0]->r) >
lighterr // perfect mip even if
// light is not exactly
// equal
|| abs(o[i + 1]->g - o[0]->g) >
lighterr ||
abs(o[i + 1]->b - o[0]->b) >
lighterr ||
o[i]->utex != o[3]->utex ||
o[i]->wtex != o[3]->wtex)
goto c;
}
if (r->type == CHF ||
r->type ==
FHF) // can make a perfect mip out of a
// hf if slopes lie on one line
{
if (o[0]->vdelta - o[1]->vdelta !=
o[1]->vdelta -
SWS(w, x + 2, y, ws)
->vdelta ||
o[0]->vdelta - o[2]->vdelta !=
o[2]->vdelta -
SWS(w, x + 2, y + 2, ws)
|
|
>
|
<
|
>
<
|
|
>
<
|
<
|
<
|
>
>
<
|
<
|
|
|
|
>
>
<
|
|
|
|
|
|
|
>
|
|
<
|
|
>
>
>
|
<
<
|
|
<
|
|
<
>
|
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
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
|
// 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;
loopk(MAXTYPE) if (nums[k] == 4) r->type = k;
if (!SOLID(r)) {
int floor = 127, ceil = -128, num = 0;
loopi(4) if (!SOLID(o[i]))
{
num++;
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)) {
loopi(3)
{
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 {
loopi(3)
{
// 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 ||
abs(o[i + 1]->r - o[0]->r) >
lighterr ||
abs(o[i + 1]->g - o[0]->g) >
lighterr ||
abs(o[i + 1]->b - o[0]->b) >
lighterr ||
o[i]->utex != o[3]->utex ||
o[i]->wtex != o[3]->wtex)
goto c;
}
// can make a perfect mip out of a hf if slopes
// lie on one line
if (r->type == CHF || r->type == FHF) {
if (o[0]->vdelta - o[1]->vdelta !=
o[1]->vdelta -
SWS(w, x + 2, y, ws)
->vdelta ||
o[0]->vdelta - o[2]->vdelta !=
o[2]->vdelta -
SWS(w, x + 2, y + 2, ws)
|
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
o[2]->vdelta -
SWS(w, x + 1, y + 2, ws)
->vdelta)
goto c;
}
}
{
loopi(4) if (o[i]->defer) goto c;
} // if any of the constituents is not perfect, then
// this one isn't either
mip:
r->defer = 0;
c:;
}
s.x /= 2;
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++;
if (bb.ys < ssize - 3)
bb.ys++;
remip(bb, level);
}
int
closestent() // used for delent and edit mode ent display
{
if (noteditmode())
return -1;
|
<
|
|
>
>
|
|
|
>
>
|
|
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
o[2]->vdelta -
SWS(w, x + 1, y + 2, ws)
->vdelta)
goto c;
}
}
{
// if any of the constituents is not perfect,
// then this one isn't either
loopi(4) if (o[i]->defer) goto c;
}
mip:
r->defer = 0;
c:;
}
s.x /= 2;
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++;
if (bb.ys < ssize - 3)
bb.ys++;
remip(&bb, level);
}
int
closestent() // used for delent and edit mode ent display
{
if (noteditmode())
return -1;
|
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
|
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);
toggleedit();
|
|
|
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
|
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);
toggleedit();
|