-
Notifications
You must be signed in to change notification settings - Fork 5
/
r_lights.pas
117 lines (104 loc) · 3.58 KB
/
r_lights.pas
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
//------------------------------------------------------------------------------
//
// FPCDoom - Port of Doom to Free Pascal Compiler
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 2004-2007 by Jim Valavanis
// Copyright (C) 2017-2022 by Jim Valavanis
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
//------------------------------------------------------------------------------
// E-Mail: [email protected]
// Site : https://sourceforge.net/projects/fpcdoom/
//------------------------------------------------------------------------------
{$I FPCDoom.inc}
unit r_lights;
interface
uses
d_fpc;
const
LIGHTBOOSTSIZE = 128;
type
lpost_t = record
topdelta: integer;
length: integer; // length data bytes follows
end;
Plpost_t = ^lpost_t;
var
lightexturelookup: array[0..LIGHTBOOSTSIZE - 1] of lpost_t;
lighttexture: PLongWordArray = nil;
//==============================================================================
//
// R_InitLightTexture
//
//==============================================================================
procedure R_InitLightTexture;
//==============================================================================
//
// R_ShutDownLightTexture
//
//==============================================================================
procedure R_ShutDownLightTexture;
implementation
//==============================================================================
// R_InitLightTexture
//
// R_InitLights
//
//==============================================================================
procedure R_InitLightTexture;
var
i, j: integer;
dist: double;
c: LongWord;
begin
if lighttexture = nil then
lighttexture := PLongWordArray(malloc(LIGHTBOOSTSIZE * LIGHTBOOSTSIZE * SizeOf(LongWord)));
for i := 0 to LIGHTBOOSTSIZE - 1 do
begin
lightexturelookup[i].topdelta := MAXINT;
lightexturelookup[i].length := 0;
for j := 0 to LIGHTBOOSTSIZE - 1 do
begin
dist := sqrt(sqr(i - (LIGHTBOOSTSIZE shr 1)) + sqr(j - (LIGHTBOOSTSIZE shr 1)));
if dist <= (LIGHTBOOSTSIZE shr 1) then
begin
inc(lightexturelookup[i].length);
c := Round(dist * 4);
if c > 255 then
c := 0
else
c := 255 - c;
lighttexture[i * LIGHTBOOSTSIZE + j] := c * 255;
if j < lightexturelookup[i].topdelta then
lightexturelookup[i].topdelta := j;
end
else
lighttexture[i * LIGHTBOOSTSIZE + j] := 0;
end;
end;
end;
//==============================================================================
//
// R_ShutDownLightTexture
//
//==============================================================================
procedure R_ShutDownLightTexture;
begin
if lighttexture <> nil then
memfree(lighttexture, LIGHTBOOSTSIZE * LIGHTBOOSTSIZE * SizeOf(LongWord));
end;
end.