Cube  Diff

Differences From Artifact [5df422a1d9]:

To Artifact [ecc6786def]:


161
162
163
164
165
166
167
168

169
170
171
172
173
174
175
161
162
163
164
165
166
167

168
169
170
171
172
173
174
175







-
+







	        SW(s, 1, -1)->m + SW(s, -1, 1)->m + SW(s, -1, -1)->m) /      \
	    14; // median is 4/2/1 instead
		median(r);
		median(g);
		median(b);
	}

	remip(a);
	remip(&a);
}

void
calclight()
{
	loop(x, ssize) loop(y, ssize)
	{
192
193
194
195
196
197
198
199

200
201
202
203
204
205

206
207
208
209
210
211
212
213
214

215
216
217
218

219
220
221
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

266
267
268
269



270
271
272
192
193
194
195
196
197
198

199
200
201
202
203
204

205
206
207
208
209
210
211
212
213

214
215
216
217

218
219
220
221
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
266



267
268
269
270
271
272







-
+





-
+








-
+



-
+
















-
+



-
-
-
+
+
+










-
+


-
-
+
+

-
-
+
+





-
+

-
-
-
+
+
+




void
cleardlights()
{
	while (dlights.count > 0) {
		block *backup = *(block **)[dlights lastItem];
		[dlights removeLastItem];
		blockpaste(*backup);
		blockpaste(backup);
		OFFreeMemory(backup);
	}
}

void
dodynlight(const OFVector3D &vold, const OFVector3D &v, int reach, int strength,
dodynlight(const OFVector3D *vold, const OFVector3D *v, int reach, int strength,
    DynamicEntity *owner)
{
	if (!reach)
		reach = dynlight;
	if (owner.monsterstate)
		reach = reach / 2;
	if (!reach)
		return;
	if (v.x < 0 || v.y < 0 || v.x > ssize || v.y > ssize)
	if (v->x < 0 || v->y < 0 || v->x > ssize || v->y > ssize)
		return;

	int creach = reach + 16; // dependant on lightray random offsets!
	block b = { (int)v.x - creach, (int)v.y - creach, creach * 2 + 1,
	block b = { (int)v->x - creach, (int)v->y - creach, creach * 2 + 1,
		creach * 2 + 1 };

	if (b.x < 1)
		b.x = 1;
	if (b.y < 1)
		b.y = 1;
	if (b.xs + b.x > ssize - 2)
		b.xs = ssize - 2 - b.x;
	if (b.ys + b.y > ssize - 2)
		b.ys = ssize - 2 - b.y;

	if (dlights == nil)
		dlights =
		    [[OFMutableData alloc] initWithItemSize:sizeof(block *)];

	// backup area before rendering in dynlight
	block *copy = blockcopy(b);
	block *copy = blockcopy(&b);
	[dlights addItem:&copy];

	PersistentEntity *l = [Entity entity];
	l.x = v.x;
	l.y = v.y;
	l.z = v.z;
	l.x = v->x;
	l.y = v->y;
	l.z = v->z;
	l.attr1 = reach;
	l.type = LIGHT;
	l.attr2 = strength;
	calclightsource(l);
	postlightarea(b);
}

// utility functions also used by editing code

block *
blockcopy(block &s)
blockcopy(const block *s)
{
	block *b = (block *)OFAllocZeroedMemory(
	    1, sizeof(block) + s.xs * s.ys * sizeof(sqr));
	*b = s;
	    1, sizeof(block) + s->xs * s->ys * sizeof(sqr));
	*b = *s;
	sqr *q = (sqr *)(b + 1);
	for (int x = s.x; x < s.xs + s.x; x++)
		for (int y = s.y; y < s.ys + s.y; y++)
	for (int x = s->x; x < s->xs + s->x; x++)
		for (int y = s->y; y < s->ys + s->y; y++)
			*q++ = *S(x, y);
	return b;
}

void
blockpaste(const block &b)
blockpaste(const block *b)
{
	sqr *q = (sqr *)((&b) + 1);
	for (int x = b.x; x < b.xs + b.x; x++)
		for (int y = b.y; y < b.ys + b.y; y++)
	sqr *q = (sqr *)(b + 1);
	for (int x = b->x; x < b->xs + b->x; x++)
		for (int y = b->y; y < b->ys + b->y; y++)
			*S(x, y) = *q++;
	remipmore(b);
}