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, PersistentEntity *light)
{
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)
|
<
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
// worldlight.cpp
#include "cube.h"
#import "DynamicEntity.h"
#import "Entity.h"
extern bool hasoverbright;
VAR(lightscale, 1, 4, 100);
// done in realtime, needs to be fast
void
lightray(float bx, float by, Entity *light)
{
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)
|
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
fast_f2nat(l / (float)steps); // incorrect: light will fade quicker
// if near edge of the world
if (hasoverbright) {
l /= lightscale;
stepl /= lightscale;
if (light.attr3 ||
light.attr4) // coloured light version, special case because
// most lights are white
{
int dimness = rnd(
(255 -
(light.attr2 + light.attr3 + light.attr4) / 3) /
16 +
1);
x += stepx * dimness;
y += stepy * dimness;
|
<
|
|
<
>
|
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
fast_f2nat(l / (float)steps); // incorrect: light will fade quicker
// if near edge of the world
if (hasoverbright) {
l /= lightscale;
stepl /= lightscale;
// coloured light version, special case because most lights are
// white
if (light.attr3 || light.attr4) {
int dimness = rnd(
(255 -
(light.attr2 + light.attr3 + light.attr4) / 3) /
16 +
1);
x += stepx * dimness;
y += stepy * dimness;
|
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
y += stepy;
l -= stepl;
}
}
}
void
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;
|
|
|
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
y += stepy;
l -= stepl;
}
}
}
void
calclightsource(Entity *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;
|
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
dlights = [[OFMutableData alloc]
initWithItemSize:sizeof(struct block *)];
// backup area before rendering in dynlight
struct block *copy = blockcopy(&b);
[dlights addItem:©];
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);
|
|
|
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
dlights = [[OFMutableData alloc]
initWithItemSize:sizeof(struct block *)];
// backup area before rendering in dynlight
struct block *copy = blockcopy(&b);
[dlights addItem:©];
Entity *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);
|