Cube  Diff

Differences From Artifact [05fab5d192]:

To Artifact [a6b73ab397]:


1
2
3
4
5


6
7
8
9
10

11
12

13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14

15

16
17
18
19
20
21
22





+
+





+

-
+
-







// worldlight.cpp

#include "cube.h"

#import "DynamicEntity.h"
#import "Entity.h"
#import "PersistentEntity.h"

extern bool hasoverbright;

VAR(lightscale, 1, 4, 100);

// done in realtime, needs to be fast
void
lightray(float bx, float by,
lightray(float bx, float by, PersistentEntity *light)
    persistent_entity &light) // done in realtime, needs to be fast
{
	float lx = light.x + (rnd(21) - 10) * 0.1f;
	float ly = light.y + (rnd(21) - 10) * 0.1f;
	float dx = bx - lx;
	float dy = by - ly;
	float dist = (float)sqrt(dx * dx + dy * dy);
	if (dist < 1.0f)
117
118
119
120
121
122
123
124

125
126
127
128
129
130
131
119
120
121
122
123
124
125

126
127
128
129
130
131
132
133







-
+







			y += stepy;
			l -= stepl;
		}
	}
}

void
calclightsource(persistent_entity &l)
calclightsource(PersistentEntity *l)
{
	int reach = l.attr1;
	int sx = l.x - reach;
	int ex = l.x + reach;
	int sy = l.y - reach;
	int ey = l.y + reach;

171
172
173
174
175
176
177
178

179
180
181
182
183
184
185
186
187
188
189
190
173
174
175
176
177
178
179

180


181
182

183
184
185
186
187
188
189







-
+
-
-


-







{
	loop(x, ssize) loop(y, ssize)
	{
		sqr *s = S(x, y);
		s->r = s->g = s->b = 10;
	}

	loopv(ents)
	for (Entity *e in ents)
	{
		entity &e = ents[i];
		if (e.type == LIGHT)
			calclightsource(e);
	}

	block b = { 1, 1, ssize - 2, ssize - 2 };
	postlightarea(b);
	setvar(@"fullbright", 0);
}

VARP(dynlight, 0, 16, 32);
232
233
234
235
236
237
238
239
240







241
242
243
244
245
246
247
231
232
233
234
235
236
237


238
239
240
241
242
243
244
245
246
247
248
249
250
251







-
-
+
+
+
+
+
+
+







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

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

	persistent_entity l = { (short)v.x, (short)v.y, (short)v.z,
		(short)reach, LIGHT, (uchar)strength, 0, 0 };
	PersistentEntity *l = [Entity entity];
	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 *