Debian Codegraph @

Descent3/terrain.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifdef NEWEDITOR
20 #include "neweditor\globals.h"
21 #else
22 #include <stdlib.h>
23 #endif
24 #include "vecmat.h"cxx . . $ `<file>/lib/vecmat.h`/
25 #include "object.h"cxx . . $ `<file>/Descent3/object.h`/
26 #include "mono.h"cxx . . $ `<file>/ddebug/mono.h`/
27 #include "terrain.h"cxx . . $ `<file>/Descent3/terrain.h`/
28 #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/
29 #include "bitmap.h"cxx . . $ `<file>/lib/bitmap.h`/
30 #include "gametexture.h"cxx . . $ `<file>/Descent3/gametexture.h`/
31 #include "lighting.h"cxx . . $ `<file>/Descent3/lighting.h`/
32 #include "lightmap.h"cxx . . $ `<file>/lib/lightmap.h`/
33 #include "weather.h"cxx . . $ `<file>/Descent3/weather.h`/
34 #include <string.h>
35 #include "mem.h"cxx . . $ `<file>/mem/mem.h`/
36 #include "dedicated_server.h"cxx . . $ `<file>/lib/dedicated_server.h`/
37 #include "psrand.h"cxx . . $ `<file>/misc/psrand.h`/
38 #ifdef EDITOR
39 #include "editor\d3edit.h"
40 #endif
41
42 #include <algorithm>
43
44 #define SKY_RADIUScxx . . $ `Descent3/terrain.cpp:44:9`! 2500.0
45 #define DEFAULT_LIGHT_SOURCEcxx . . $ `Descent3/terrain.cpp:45:9`! \
46 { 0, TERRAIN_SIZE * 100, 0 }
47
48 // How far we can see (in world coordinates)
49 float VisibleTerrainZcxx . . $ VisibleTerrainZ.;
50
51 terrain_segmentcxx . . $ terrain_segment# Terrain_segcxx . . $ Terrain_seg.[TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! * TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!];
52 terrain_tex_segmentcxx . . $ terrain_tex_segment# Terrain_tex_segcxx . . $ Terrain_tex_seg.[TERRAIN_TEX_WIDTHcxx . . $ `Descent3/terrain.h:34:9`! * TERRAIN_TEX_DEPTHcxx . . $ `Descent3/terrain.h:35:9`!];
53 terrain_skycxx . . $ terrain_sky# Terrain_skycxx . . $ Terrain_sky.;
54
55 #if (!defined(RELEASE) || defined(NEWEDITOR))
56 // first object to render after cell has been rendered (only used for SW renderer)
57 int16_t Terrain_seg_render_objscxx . . $ Terrain_seg_render_objs.[TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! * TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!];
58 #endif
59
60 // Our lighting maps for the terrain, one for each quadrant (starting at lower left)
61 int TerrainLightmapscxx . . $ TerrainLightmaps.[4];
62
63 // A list of terrain to render
64 terrain_render_infocxx . . $ terrain_render_info# Terrain_listcxx . . $ Terrain_list.[MAX_CELLS_TO_RENDERcxx . . $ `Descent3/terrain.h:44:9`!];
65
66 uint16_tcxx . . $ uint16_t# *Terrain_rotate_listcxx . . $ Terrain_rotate_list.; // which points have been sub/rotated this frame
67 g3Pointcxx . . $ g3Point# *World_point_buffercxx . . $ World_point_buffer.; // Rotated points
68
69 // The min/max values for a particular region of terrain
70 uint8_tcxx . . $ uint8_t# *Terrain_min_height_intcxx . . $ Terrain_min_height_int.[7];
71 uint8_tcxx . . $ uint8_t# *Terrain_max_height_intcxx . . $ Terrain_max_height_int.[7];
72 // Texture values for a particular region
73
74 // Terrain dynamic lighting table
75 uint8_tcxx . . $ uint8_t# Terrain_dynamic_tablecxx . . $ Terrain_dynamic_table.[TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! * TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!];
76
77 // Terrain normals depending on LOD
78 terrain_normalscxx . . $ terrain_normals# *TerrainNormalscxx . . $ TerrainNormals.[MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`!];
79
80 // Max deltas per terrain lod block
81 float *TerrainDeltaBlockscxx . . $ TerrainDeltaBlocks.[MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`!];
82
83 // Tracks edges of LOD
84 uint8_tcxx . . $ uint8_t# TerrainJoinMapcxx . . $ TerrainJoinMap.[TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! * TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!];
85
86 // Terrain Y values
87 float Terrain_y_valuescxx . . $ Terrain_y_values.[256];
88
89 #if (defined(EDITOR) || defined(NEWEDITOR))
90 uint8_t TerrainSelected[TERRAIN_WIDTH * TERRAIN_DEPTH];
91 int Num_terrain_selected = 0;
92 int Editor_LOD_engine_off = 1;
93 bool Terrain_render_ext_room_objs = true;
94 #endif
95
96 int TSearch_oncxx . . $ TSearch_on. = 0, TSearch_found_typecxx . . $ TSearch_found_type., TSearch_xcxx . . $ TSearch_x., TSearch_ycxx . . $ TSearch_y., TSearch_segcxx . . $ TSearch_seg., TSearch_facecxx . . $ TSearch_face.;
97
98 int Terrain_LOD_engine_offcxx . . $ Terrain_LOD_engine_off. = 0;
99
100 int TerrainEdgeTestcxx . . $ TerrainEdgeTest.[MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`!][16];
101 uint8_tcxx . . $ uint8_t# TerrainEdgeJumpcxx . . $ TerrainEdgeJump.[MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`!];
102
103 // Unique terrain geometry identifier
104 int Terrain_checksumcxx . . $ Terrain_checksum. = -1;
105
106 // Occlusion data for knowing what to draw
107 uint8_tcxx . . $ uint8_t# Terrain_occlusion_mapcxx . . $ Terrain_occlusion_map.[256][32];
108 int Terrain_occlusion_checksumcxx . . $ Terrain_occlusion_checksum. = -2;
109
110 // returns the index of the highest float
111 int GetHighestDeltacxx . . $ GetHighestDelta(6ff0db6c2eaac5cf).(float *deltas, int count) {
112 int high_index = -999;
113 float high_delta = -99999;
114 int i;
115
116 for (i = 0; i < count; i++) {
117 if ((deltas[i]) > (high_delta)) {
118 high_index = i;
119 high_delta = deltas[i];
120 }
121 }
122
123 ASSERTcxx . . $ `misc/pserror.h:246:9`!(high_index < count);
124
125 return high_index;
126 }
127
128 float RecurseLODDeltascxx . . $ RecurseLODDeltas(463a696484ba7200).(int x1, int y1, int x2, int y2, int lod) {
129 float deltas[6];
130 float maxdelta;
131 float v0, v1, v2, v3;
132 int edgex = x2, edgey = y2;
133 int i, t;
134
135 if (x1 % 2)
136 Int3cxx . . $ `misc/pserror.h:247:9`!();
137 if (x2 % 2)
138 Int3cxx . . $ `misc/pserror.h:247:9`!();
139 if (y1 % 2)
140 Int3cxx . . $ `misc/pserror.h:247:9`!();
141 if (y2 % 2)
142 Int3cxx . . $ `misc/pserror.h:247:9`!();
143
144 int midx = ((x2 - x1) / 2) + x1;
145 int midy = ((y2 - y1) / 2) + y1;
146
147 if (x2 == TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!)
148 edgex = TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! - 1;
149 if (y2 == TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!)
150 edgey = TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`! - 1;
151
152 // starts from lower left, proceeds clockwise
153 v0 = Terrain_segcxx . . $ Terrain_seg.[y1 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + x1].ycxx . . $ terrain_segment#y.;
154 v1 = Terrain_segcxx . . $ Terrain_seg.[edgey * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + x1].ycxx . . $ terrain_segment#y.;
155 v2 = Terrain_segcxx . . $ Terrain_seg.[edgey * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + edgex].ycxx . . $ terrain_segment#y.;
156 v3 = Terrain_segcxx . . $ Terrain_seg.[y1 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + edgex].ycxx . . $ terrain_segment#y.;
157
158 deltas[0] = fabscxx . . $ fabs(fbcf3211dfe1bfd1).(Terrain_segcxx . . $ Terrain_seg.[(midy)*TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + midx].ycxx . . $ terrain_segment#y. - (((v2 - v0) / 2) + v0));
159 deltas[1] = fabscxx . . $ fabs(fbcf3211dfe1bfd1).(Terrain_segcxx . . $ Terrain_seg.[(midy)*TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + midx].ycxx . . $ terrain_segment#y. - (((v3 - v1) / 2) + v1));
160
161 // left edge
162 deltas[2] = fabscxx . . $ fabs(fbcf3211dfe1bfd1).(Terrain_segcxx . . $ Terrain_seg.[(midy)*TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + x1].ycxx . . $ terrain_segment#y. - (((v1 - v0) / 2) + v0));
163
164 // top edge
165 deltas[3] = fabscxx . . $ fabs(fbcf3211dfe1bfd1).(Terrain_segcxx . . $ Terrain_seg.[(y2)*TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + midx].ycxx . . $ terrain_segment#y. - (((v2 - v1) / 2) + v1));
166
167 // right edge
168 deltas[4] = fabscxx . . $ fabs(fbcf3211dfe1bfd1).(Terrain_segcxx . . $ Terrain_seg.[(midy)*TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + x2].ycxx . . $ terrain_segment#y. - (((v3 - v2) / 2) + v2));
169
170 // bottom edge
171 deltas[5] = fabscxx . . $ fabs(fbcf3211dfe1bfd1).(Terrain_segcxx . . $ Terrain_seg.[(y1)*TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + midx].ycxx . . $ terrain_segment#y. - (((v3 - v0) / 2) + v0));
172
173 maxdelta = deltas[GetHighestDeltacxx . . $ GetHighestDelta(6ff0db6c2eaac5cf).(deltas, 6)];
174
175 if (lod != MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 2) {
176 deltas[0] = RecurseLODDeltascxx . . $ RecurseLODDeltas(463a696484ba7200).(x1, midy, midx, y2, lod + 1);
177 deltas[1] = RecurseLODDeltascxx . . $ RecurseLODDeltas(463a696484ba7200).(midx, midy, x2, y2, lod + 1);
178 deltas[2] = RecurseLODDeltascxx . . $ RecurseLODDeltas(463a696484ba7200).(midx, y1, x2, midy, lod + 1);
179 deltas[3] = RecurseLODDeltascxx . . $ RecurseLODDeltas(463a696484ba7200).(x1, y1, midx, midy, lod + 1);
180
181 if (deltas[0] == SHUTOFF_LOD_INVISIBLEcxx . . $ `Descent3/terrain.h:40:9`! && deltas[1] == SHUTOFF_LOD_INVISIBLEcxx . . $ `Descent3/terrain.h:40:9`! &&
182 deltas[2] == SHUTOFF_LOD_INVISIBLEcxx . . $ `Descent3/terrain.h:40:9`! && deltas[3] == SHUTOFF_LOD_INVISIBLEcxx . . $ `Descent3/terrain.h:40:9`!) {
183 maxdelta = SHUTOFF_LOD_INVISIBLEcxx . . $ `Descent3/terrain.h:40:9`!;
184 } else {
185 for (i = 0; i < 4; i++) {
186 if (deltas[i] == SHUTOFF_LOD_INVISIBLEcxx . . $ `Descent3/terrain.h:40:9`!)
187 deltas[i] = SHUTOFF_LOD_DELTAcxx . . $ `Descent3/terrain.h:39:9`!;
188 }
189
190 float maxdelta2 = deltas[GetHighestDeltacxx . . $ GetHighestDelta(6ff0db6c2eaac5cf).(deltas, 4)];
191 if (maxdelta2 > maxdelta)
192 maxdelta = maxdelta2;
193 }
194 }
195
196 // Now check if there is anything special about this level of detail that
197 // excludes it from being used in the engine
198 if (lod == MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 2) {
199 int total_counted = 0, total_invis = 0;
200
201 for (i = y1; i < y2; i++) {
202 for (t = x1; t < x2; t++, total_counted++) {
203 if ((Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t].flagscxx . . $ terrain_segment#flags. & TF_INVISIBLEcxx . . $ `Descent3/terrain.h:76:9`!)) {
204 maxdelta = SHUTOFF_LOD_DELTAcxx . . $ `Descent3/terrain.h:39:9`!;
205 total_invis++;
206 }
207 }
208 }
209
210 // See if we can completely turn off this LOD
211 if (total_invis == total_counted)
212 maxdelta = SHUTOFF_LOD_INVISIBLEcxx . . $ `Descent3/terrain.h:40:9`!;
213 }
214
215 return (maxdelta);
216 }
217
218 // returns highest slopechange
219 float GetGreatestSlopeChangecxx . . $ GetGreatestSlopeChange(779de2cc40116283).(float *slopes, int count) {
220 float high_delta = -90000.0f;
221 int i, t;
222
223 for (i = 0; i < count; i++) {
224 for (t = 0; t < count; t++) {
225 if ((fabscxx . . $ fabs(fbcf3211dfe1bfd1).(slopes[t] - slopes[i])) > high_delta) {
226 high_delta = fabscxx . . $ fabs(fbcf3211dfe1bfd1).(slopes[t] - slopes[i]);
227 }
228 }
229 }
230
231 return high_delta;
232 }
233
234 void GenerateSingleLODDeltacxx . . $ GenerateSingleLODDelta(3e454b8ccf442868).(int sx, int sz) {
235 int w, h, i, z, x;
236 int simplemul, rowsize;
237 int chunk_size = 1 << (MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1);
238
239 sx *= chunk_size;
240 sz *= chunk_size;
241
242 int save_x = sx;
243 int save_z = sz;
244
245 // Starts from lower-left, going clockwise
246 // 0 is lowest_level_detail (blunt)
247 for (i = 0; i < MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1; i++) {
248 w = chunk_size >> ((MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1) - i);
249 h = chunk_size >> ((MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1) - i);
250
251 simplemul = 1 << ((MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1) - i);
252 rowsize = TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! / simplemul;
253
254 sx = save_x;
255 sz = save_z;
256
257 sx /= simplemul;
258 sz /= simplemul;
259
260 for (z = sz; z < sz + h; z++) {
261 for (x = sx; x < sx + w; x++) {
262 float delta;
263
264 delta =
265 RecurseLODDeltascxx . . $ RecurseLODDeltas(463a696484ba7200).(x * simplemul, (z * simplemul), (x * simplemul) + simplemul, z * simplemul + simplemul, i);
266 TerrainDeltaBlockscxx . . $ TerrainDeltaBlocks.[i][z * rowsize + x] = delta;
267 }
268 }
269 }
270 }
271
272 void GenerateLODDeltascxx . . $ GenerateLODDeltas(49f6e7a06ebc5aa8).() {
273 int w, h, i, z, x;
274 int simplemul, rowsize;
275 // Starts from lower-left, going clockwise
276 for (i = 0; i < MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1; i++) {
277 w = TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! >> ((MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1) - i);
278 h = TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`! >> ((MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1) - i);
279
280 simplemul = 1 << ((MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1) - i);
281 rowsize = TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! / simplemul;
282
283 for (z = 0; z < h; z++) {
284 for (x = 0; x < w; x++) {
285 float delta;
286
287 delta =
288 RecurseLODDeltascxx . . $ RecurseLODDeltas(463a696484ba7200).(x * simplemul, (z * simplemul), (x * simplemul) + simplemul, z * simplemul + simplemul, i);
289 TerrainDeltaBlockscxx . . $ TerrainDeltaBlocks.[i][z * rowsize + x] = delta;
290 }
291 }
292 }
293 }
294
295 // Returns a unique checksum for the current terrain geometry
296 int GetTerrainGeometryChecksumcxx . . $ GetTerrainGeometryChecksum(b126dc7c1de90089).() {
297 int total = 0;
298
299 for (int i = 0; i < TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! * TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!; i++) {
300 total += (Terrain_segcxx . . $ Terrain_seg.[i].yposcxx . . $ terrain_segment#ypos. + i);
301 }
302
303 return total;
304 }
305
306 // Builds the min max quadtree data for terrain VSD
307 void BuildMinMaxTerraincxx . . $ BuildMinMaxTerrain(49f6e7a06ebc5aa8).() {
308 int i, w, h, start, x, y, cell;
309 int row_width, xoffset, yoffset, total_rows;
310 int minheight, maxheight, cellheight;
311
312 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Building min/max terrain table.\n");
313
314 // Calculate our integer y positions (0-255)
315 for (i = 0; i < TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! * TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!; i++) {
316 float fl;
317
318 #if (!defined(RELEASE) || defined(NEWEDITOR))
319 Terrain_seg_render_objscxx . . $ Terrain_seg_render_objs.[i] = -1;
320 #endif
321
322 fl = Terrain_segcxx . . $ Terrain_seg.[i].yposcxx . . $ terrain_segment#ypos. * TERRAIN_HEIGHT_INCREMENTcxx . . $ `Descent3/terrain.h:47:9`!;
323
324 Terrain_segcxx . . $ Terrain_seg.[i].ycxx . . $ terrain_segment#y. = fl;
325 }
326
327 int check = GetTerrainGeometryChecksumcxx . . $ GetTerrainGeometryChecksum(b126dc7c1de90089).();
328
329 if (check == Terrain_checksumcxx . . $ Terrain_checksum.)
330 return;
331
332 Terrain_checksumcxx . . $ Terrain_checksum. = check;
333
334 // Generate level of detail deltas
335 if (!Dedicated_servercxx . . $ Dedicated_server.)
336 GenerateLODDeltascxx . . $ GenerateLODDeltas(49f6e7a06ebc5aa8).();
337
338 for (i = 0; i < 7; i++) {
339 row_width = 1 << i;
340 total_rows = 1 << i;
341 int yspeed_offset = 0;
342
343 for (yoffset = 0; yoffset < total_rows; yoffset++, yspeed_offset += row_width) {
344 for (xoffset = 0; xoffset < row_width; xoffset++) {
345 w = TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! >> i;
346 h = TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! >> i;
347
348 start = ((yoffset * (TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! >> i)) * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!);
349 start += (xoffset * (TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! >> i));
350
351 minheight = 999;
352 maxheight = 0;
353
354 if (h < TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!)
355 h++;
356 if (w < TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!)
357 w++;
358
359 int terrain_offset = 0;
360 for (y = 0; y < h; y++, terrain_offset += TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!) {
361 for (x = 0; x < w; x++) {
362 cell = start + (terrain_offset) + x;
363 cellheight = Terrain_segcxx . . $ Terrain_seg.[cell].yposcxx . . $ terrain_segment#ypos.;
364
365 if (cellheight < minheight)
366 minheight = cellheight;
367 if (cellheight > maxheight)
368 maxheight = cellheight;
369 }
370 }
371
372 if (minheight < 0)
373 minheight = 0;
374 if (maxheight > 255)
375 maxheight = 255;
376
377 Terrain_min_height_intcxx . . $ Terrain_min_height_int.[i][yspeed_offset + xoffset] = (minheight);
378 Terrain_max_height_intcxx . . $ Terrain_max_height_int.[i][yspeed_offset + xoffset] = (maxheight);
379 }
380 }
381 }
382 }
383
384 // Changes the terrain mesh for deformation effect
385 void DeformTerrainPointcxx . . $ DeformTerrainPoint(b1146eedae1e1d0b).(int x, int z, int change_height) {
386 terrain_segmentcxx . . $ terrain_segment# *tseg = &Terrain_segcxx . . $ Terrain_seg.[z * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + x];
387 int i;
388
389 change_height += tseg->yposcxx . . $ terrain_segment#ypos.;
390
391 change_height = stdcxx . . $ std/::clampcxx . . $ std/clamp(3dbe0c69cb86ae06).(change_height, 0, 255);
392
393 tseg->yposcxx . . $ terrain_segment#ypos. = change_height;
394 tseg->ycxx . . $ terrain_segment#y. = tseg->yposcxx . . $ terrain_segment#ypos. * TERRAIN_HEIGHT_INCREMENTcxx . . $ `Descent3/terrain.h:47:9`!;
395
396 int sx = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(0, x - 1);
397 int sz = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(0, z - 1);
398
399 // Update min/max
400 for (i = 0; i < 7; i++) {
401 int row_width = 1 << i;
402 int div = 256 >> i;
403
404 for (int t = sz; t <= z; t++) {
405 for (int k = sx; k <= x; k++) {
406
407 int offset = ((t / div) * row_width) + (k / div);
408
409 if (tseg->yposcxx . . $ terrain_segment#ypos. > Terrain_max_height_intcxx . . $ Terrain_max_height_int.[i][offset])
410 Terrain_max_height_intcxx . . $ Terrain_max_height_int.[i][offset] = tseg->yposcxx . . $ terrain_segment#ypos.;
411 if (tseg->yposcxx . . $ terrain_segment#ypos. < Terrain_min_height_intcxx . . $ Terrain_min_height_int.[i][offset])
412 Terrain_min_height_intcxx . . $ Terrain_min_height_int.[i][offset] = tseg->yposcxx . . $ terrain_segment#ypos.;
413 }
414 }
415 }
416
417 // Update normals
418
419 for (i = sz; i <= z; i++) {
420 for (int t = sx; t <= x; t++) {
421 vectorcxx . . $ vector# a, b, c;
422 terrain_segmentcxx . . $ terrain_segment# *tseg0 = &Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t];
423 terrain_segmentcxx . . $ terrain_segment# *tseg1 = &Terrain_segcxx . . $ Terrain_seg.[(i + 1) * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t];
424 terrain_segmentcxx . . $ terrain_segment# *tseg2 = &Terrain_segcxx . . $ Terrain_seg.[((i + 1) * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!) + t + 1];
425 terrain_segmentcxx . . $ terrain_segment# *tseg3 = &Terrain_segcxx . . $ Terrain_seg.[(i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!) + t + 1];
426
427 // Do upper left triangle
428 a.xcxx . . $ vector#x. = t * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
429 a.ycxx . . $ vector#y. = tseg0->ycxx . . $ terrain_segment#y.;
430 a.zcxx . . $ vector#z. = i * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
431
432 b.xcxx . . $ vector#x. = t * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
433 b.ycxx . . $ vector#y. = tseg1->ycxx . . $ terrain_segment#y.;
434 b.zcxx . . $ vector#z. = (i + 1) * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
435
436 c.xcxx . . $ vector#x. = (t + 1) * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
437 c.ycxx . . $ vector#y. = tseg2->ycxx . . $ terrain_segment#y.;
438 c.zcxx . . $ vector#z. = (i + 1) * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
439
440 vm_GetNormalcxx . . $ vm_GetNormal(f84d76fdbff5e570).(&TerrainNormalscxx . . $ TerrainNormals.[MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1][i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t].normal1cxx . . $ terrain_normals#normal1., &a, &b, &c);
441
442 // Now do lower right triangle
443 a.xcxx . . $ vector#x. = t * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
444 a.ycxx . . $ vector#y. = tseg0->ycxx . . $ terrain_segment#y.;
445 a.zcxx . . $ vector#z. = i * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
446
447 b.xcxx . . $ vector#x. = (t + 1) * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
448 b.ycxx . . $ vector#y. = tseg2->ycxx . . $ terrain_segment#y.;
449 b.zcxx . . $ vector#z. = (i + 1) * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
450
451 c.xcxx . . $ vector#x. = (t + 1) * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
452 c.ycxx . . $ vector#y. = tseg3->ycxx . . $ terrain_segment#y.;
453 c.zcxx . . $ vector#z. = (i)*TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
454
455 vm_GetNormalcxx . . $ vm_GetNormal(f84d76fdbff5e570).(&TerrainNormalscxx . . $ TerrainNormals.[MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1][i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t].normal2cxx . . $ terrain_normals#normal2., &a, &b, &c);
456 }
457 }
458 }
459
460 void UpdateSingleTerrainLightmapcxx . . $ UpdateSingleTerrainLightmap(d4f767463ce0a6b3).(int which);
461 void DeformTerraincxx . . $ DeformTerrain(15ae840579c16834).(vectorcxx . . $ vector# *pos, int depth, float size) {
462 int startx, startz, endx, endz;
463 int changed[4] = {0, 0, 0, 0};
464 vectorcxx . . $ vector# local_pos = *pos;
465
466 startx = (pos->xcxx . . $ vector#x. / TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!) - (size / TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!);
467 startz = (pos->zcxx . . $ vector#z. / TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!) - (size / TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!);
468 endx = (pos->xcxx . . $ vector#x. / TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!) + (size / TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!);
469 endz = (pos->zcxx . . $ vector#z. / TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!) + (size / TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!);
470
471 startx = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(0, startx);
472 startz = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(0, startz);
473 endx = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! - 1, endx);
474 endz = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`! - 1, endz);
475
476 int i, t;
477
478 vectorcxx . . $ vector# cur_vec;
479 vectorcxx . . $ vector# up_vec = {0, 1, 0};
480
481 local_pos.ycxx . . $ vector#y. = 0;
482
483 cur_vec.xcxx . . $ vector#x. = startx * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
484 cur_vec.ycxx . . $ vector#y. = 0;
485 cur_vec.zcxx . . $ vector#z. = startz * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
486
487 float max_dist = vm_VectorDistanceQuickcxx . . $ vm_VectorDistanceQuick(a0b9c8659ecc16b8).(&local_pos, &cur_vec);
488
489 for (i = startz; i <= endz; i++, cur_vec.zcxx . . $ vector#z. += TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!) {
490 cur_vec.xcxx . . $ vector#x. = startx * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
491 for (t = startx; t <= endx; t++, cur_vec.xcxx . . $ vector#x. += TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!) {
492 terrain_segmentcxx . . $ terrain_segment# *tseg = &Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t];
493
494 if ((up_vec *cxx . . $ `operator*`(4a721543d64e126a). TerrainNormalscxx . . $ TerrainNormals.[MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1][i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t].normal1cxx . . $ terrain_normals#normal1.) < .5)
495 continue; // not flat enough
496 if ((up_vec *cxx . . $ `operator*`(4a721543d64e126a). TerrainNormalscxx . . $ TerrainNormals.[MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1][i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t].normal2cxx . . $ terrain_normals#normal2.) < .5)
497 continue; // not flat enough
498
499 float dist = 1.0 - (vm_VectorDistanceQuickcxx . . $ vm_VectorDistanceQuick(a0b9c8659ecc16b8).(&local_pos, &cur_vec) / max_dist);
500
501 int height_change = -(dist * (float)depth);
502 int light_change = height_change * 2;
503
504 DeformTerrainPointcxx . . $ DeformTerrainPoint(b1146eedae1e1d0b).(t, i, height_change);
505
506 tseg->rcxx . . $ terrain_segment#r. = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(0, tseg->rcxx . . $ terrain_segment#r. + light_change);
507 tseg->gcxx . . $ terrain_segment#g. = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(0, tseg->gcxx . . $ terrain_segment#g. + light_change);
508 tseg->bcxx . . $ terrain_segment#b. = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(0, tseg->bcxx . . $ terrain_segment#b. + light_change);
509
510 int which = ((i / 128) * 2) + (t / 128);
511 changed[which] = 1;
512 }
513 }
514
515 int div = (1 << (MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1));
516
517 startx /= div;
518 startz /= div;
519 endx /= div;
520 endz /= div;
521
522 GenerateSingleLODDeltacxx . . $ GenerateSingleLODDelta(3e454b8ccf442868).(startx, startz);
523 GenerateSingleLODDeltacxx . . $ GenerateSingleLODDelta(3e454b8ccf442868).(endx, startz);
524 GenerateSingleLODDeltacxx . . $ GenerateSingleLODDelta(3e454b8ccf442868).(endx, endz);
525 GenerateSingleLODDeltacxx . . $ GenerateSingleLODDelta(3e454b8ccf442868).(startx, endz);
526
527 for (i = 0; i < 4; i++) {
528 if (changed[i])
529 UpdateSingleTerrainLightmapcxx . . $ UpdateSingleTerrainLightmap(d4f767463ce0a6b3).(i);
530 }
531 }
532
533 // Builds normals for the currently loaded terrain
534 void BuildTerrainNormalscxx . . $ BuildTerrainNormals(49f6e7a06ebc5aa8).() {
535 int i, t, l, z, x;
536 vectorcxx . . $ vector# a, b, c;
537 int simplemul;
538 vectorcxx . . $ vector# up_norm = {0, 1.0, 0};
539
540 // Set all to be initially up
541 for (i = 0; i < TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! * TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!; i++) {
542 TerrainNormalscxx . . $ TerrainNormals.[MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1][i].normal1cxx . . $ terrain_normals#normal1. =cxx . . $ vector#`operator=`(a48bc7e93a8dae5e). up_norm;
543 TerrainNormalscxx . . $ TerrainNormals.[MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1][i].normal2cxx . . $ terrain_normals#normal2. =cxx . . $ vector#`operator=`(a48bc7e93a8dae5e). up_norm;
544 }
545
546 for (l = MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1; l < MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`!; l++) {
547 simplemul = 1 << ((MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1) - l);
548
549 for (z = 0, i = 0; i < TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`! - simplemul; i += simplemul, z++) {
550 for (x = 0, t = 0; t < TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! - simplemul; t += simplemul, x++) {
551 terrain_segmentcxx . . $ terrain_segment# *tseg = &Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t];
552 terrain_segmentcxx . . $ terrain_segment# *tseg0 = &Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t];
553 terrain_segmentcxx . . $ terrain_segment# *tseg1 = &Terrain_segcxx . . $ Terrain_seg.[(i + simplemul) * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t];
554 terrain_segmentcxx . . $ terrain_segment# *tseg2 = &Terrain_segcxx . . $ Terrain_seg.[((i + simplemul) * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!) + t + simplemul];
555 terrain_segmentcxx . . $ terrain_segment# *tseg3 = &Terrain_segcxx . . $ Terrain_seg.[(i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!) + t + simplemul];
556
557 // Do upper left triangle
558 a.xcxx . . $ vector#x. = t * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
559 a.ycxx . . $ vector#y. = tseg0->ycxx . . $ terrain_segment#y.;
560 a.zcxx . . $ vector#z. = i * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
561
562 b.xcxx . . $ vector#x. = t * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
563 b.ycxx . . $ vector#y. = tseg1->ycxx . . $ terrain_segment#y.;
564 b.zcxx . . $ vector#z. = (i + simplemul) * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
565
566 c.xcxx . . $ vector#x. = (t + simplemul) * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
567 c.ycxx . . $ vector#y. = tseg2->ycxx . . $ terrain_segment#y.;
568 c.zcxx . . $ vector#z. = (i + simplemul) * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
569
570 vm_GetNormalcxx . . $ vm_GetNormal(f84d76fdbff5e570).(&TerrainNormalscxx . . $ TerrainNormals.[l][z * (TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! / simplemul) + x].normal1cxx . . $ terrain_normals#normal1., &a, &b, &c);
571
572 // Now do lower right triangle
573 a.xcxx . . $ vector#x. = t * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
574 a.ycxx . . $ vector#y. = tseg0->ycxx . . $ terrain_segment#y.;
575 a.zcxx . . $ vector#z. = i * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
576
577 b.xcxx . . $ vector#x. = (t + simplemul) * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
578 b.ycxx . . $ vector#y. = tseg2->ycxx . . $ terrain_segment#y.;
579 b.zcxx . . $ vector#z. = (i + simplemul) * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
580
581 c.xcxx . . $ vector#x. = (t + simplemul) * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
582 c.ycxx . . $ vector#y. = tseg3->ycxx . . $ terrain_segment#y.;
583 c.zcxx . . $ vector#z. = (i)*TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
584
585 vm_GetNormalcxx . . $ vm_GetNormal(f84d76fdbff5e570).(&TerrainNormalscxx . . $ TerrainNormals.[l][z * (TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! / simplemul) + x].normal2cxx . . $ terrain_normals#normal2., &a, &b, &c);
586 }
587 }
588 }
589 }
590
591 void GenerateTerrainLightcxx . . $ GenerateTerrainLight(49f6e7a06ebc5aa8).() {
592 // Generates a lighting value for every terrain cell
593 int i;
594
595 GenerateLightSourcecxx . . $ GenerateLightSource(49f6e7a06ebc5aa8).();
596
597 vectorcxx . . $ vector# camera_light = Terrain_skycxx . . $ Terrain_sky..lightsourcecxx . . $ terrain_sky#lightsource.;
598
599 vm_NormalizeVectorcxx . . $ vm_NormalizeVector(4939a7e530383cd4).(&camera_light);
600
601 for (i = 0; i < TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! * TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!; i++) {
602 float dp = (-vm_DotProductcxx . . $ vm_DotProduct(e65d563e2b53cc54).(&camera_light, &TerrainNormalscxx . . $ TerrainNormals.[MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1][i].normal1cxx . . $ terrain_normals#normal1.) + 1.0) / 2;
603 Terrain_segcxx . . $ Terrain_seg.[i].lcxx . . $ terrain_segment#l. = Float_to_ubytecxx . . $ Float_to_ubyte(ed6d3b1f37918c01).(dp);
604 Terrain_segcxx . . $ Terrain_seg.[i].rcxx . . $ terrain_segment#r. = Terrain_segcxx . . $ Terrain_seg.[i].lcxx . . $ terrain_segment#l.;
605 Terrain_segcxx . . $ Terrain_seg.[i].gcxx . . $ terrain_segment#g. = Terrain_segcxx . . $ Terrain_seg.[i].lcxx . . $ terrain_segment#l.;
606 Terrain_segcxx . . $ Terrain_seg.[i].bcxx . . $ terrain_segment#b. = Terrain_segcxx . . $ Terrain_seg.[i].lcxx . . $ terrain_segment#l.;
607 }
608
609 UpdateTerrainLightmapscxx . . $ UpdateTerrainLightmaps(49f6e7a06ebc5aa8).();
610 }
611
612 void CloseTerraincxx . . $ CloseTerrain(49f6e7a06ebc5aa8).(void) {
613 int i;
614
615 for (i = MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1; i < MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`!; i++)
616 mem_freecxx . . $ `mem/mem.h:80:9`!(TerrainNormals[i]);
617
618 for (i = 0; i < 7; i++) {
619 if (Terrain_min_height_intcxx . . $ Terrain_min_height_int.[i])
620 mem_freecxx . . $ `mem/mem.h:80:9`!(Terrain_min_height_int[i]);
621 if (Terrain_max_height_intcxx . . $ Terrain_max_height_int.[i])
622 mem_freecxx . . $ `mem/mem.h:80:9`!(Terrain_max_height_int[i]);
623 }
624
625 if (!Dedicated_servercxx . . $ Dedicated_server.) {
626 mem_freecxx . . $ `mem/mem.h:80:9`!(Terrain_rotate_list);
627 mem_freecxx . . $ `mem/mem.h:80:9`!(World_point_buffer);
628
629 for (i = 0; i < MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1; i++)
630 mem_freecxx . . $ `mem/mem.h:80:9`!(TerrainDeltaBlocks[i]);
631 }
632 }
633
634 // Given a 3space triplet, computes the u,v coords for a texture map at that position
635 // on a sphere.
636 void SphereMapcxx . . $ SphereMap(fade194a14de6f98).(float x, float y, float z, float radius, float *u, float *v, int h) {
637 if (y < 0)
638 Int3cxx . . $ `misc/pserror.h:247:9`!();
639
640 float fh = h;
641
642 // produces u from 0 to 1
643 *u = fh / (65536.0 / 16.005); // account for floating point precision error
644
645 *v = acoscxx . . $ acos(fbcf3211dfe1bfd1).(y / radius) / (PIcxx . . $ `fix/fix.h:73:9`! / 2); // v=.5 to 1
646 *v /= .5; // v=1 to 2
647 *v -= 1; // v=0 to 1
648 }
649
650 void SetupSkyTexturecxx . . $ SetupSkyTexture(49f6e7a06ebc5aa8).() {
651
652 int first_top_texture;
653
654 // Find first sky texture
655 first_top_texture = FindTextureNamecxx . . $ FindTextureName(5c4306d8553b3696).("CloudySky");
656 if (first_top_texture < 0)
657 first_top_texture = 0;
658
659 Terrain_skycxx . . $ Terrain_sky..dome_texturecxx . . $ terrain_sky#dome_texture. = first_top_texture;
660
661 // Figure out the sky color
662
663 Terrain_skycxx . . $ Terrain_sky..sky_colorcxx . . $ terrain_sky#sky_color. = GR_RGBcxx . . $ GR_RGB(530956271a9518a5).(0, 0, 255);
664
665 if (!Terrain_skycxx . . $ Terrain_sky..texturedcxx . . $ terrain_sky#textured.)
666 Terrain_skycxx . . $ Terrain_sky..sky_colorcxx . . $ terrain_sky#sky_color. = GR_RGBcxx . . $ GR_RGB(530956271a9518a5).(8, 0, 32);
667 Terrain_skycxx . . $ Terrain_sky..fog_colorcxx . . $ terrain_sky#fog_color. = GR_RGBcxx . . $ GR_RGB(530956271a9518a5).(4, 0, 16);
668 Terrain_skycxx . . $ Terrain_sky..horizon_colorcxx . . $ terrain_sky#horizon_color. = GR_RGBcxx . . $ GR_RGB(530956271a9518a5).(128, 32, 32);
669 Terrain_skycxx . . $ Terrain_sky..texturedcxx . . $ terrain_sky#textured. = 1;
670 Terrain_skycxx . . $ Terrain_sky..rotate_ratecxx . . $ terrain_sky#rotate_rate. = 0;
671 }
672
673 // Compute a parametric sphere for our sky.
674 void SetupSkycxx . . $ SetupSky(20c5b41d67e83162).(float radius, int flags, uint8_tcxx . . $ uint8_t# randit) {
675 int jump = 65536 / MAX_HORIZON_PIECEScxx . . $ `Descent3/terrain.h:53:9`!;
676 int top = ((65536 / 4) * 3) + (65536 / 8);
677
678 int i, t;
679
680 Terrain_skycxx . . $ Terrain_sky..radiuscxx . . $ terrain_sky#radius. = radius;
681 Terrain_skycxx . . $ Terrain_sky..flagscxx . . $ terrain_sky#flags. = flags;
682
683 int horizon_r = GR_COLOR_REDcxx . . $ GR_COLOR_RED(4c679297bf94b9eb).(Terrain_skycxx . . $ Terrain_sky..horizon_colorcxx . . $ terrain_sky#horizon_color.);
684 int horizon_g = GR_COLOR_GREENcxx . . $ GR_COLOR_GREEN(4c679297bf94b9eb).(Terrain_skycxx . . $ Terrain_sky..horizon_colorcxx . . $ terrain_sky#horizon_color.);
685 int horizon_b = GR_COLOR_BLUEcxx . . $ GR_COLOR_BLUE(4c679297bf94b9eb).(Terrain_skycxx . . $ Terrain_sky..horizon_colorcxx . . $ terrain_sky#horizon_color.);
686
687 float rad_diff = radius - SKY_RADIUScxx . . $ `Descent3/terrain.cpp:44:9`!;
688
689 // Figure out where our points in the inside of the sphere are
690 for (i = 0; i < 6; i++) {
691 const int increment = 16384 / 5;
692 const anglecxx . . $ angle# pitch = (65536 - 16384) + (i * increment);
693
694 for (t = 0; t < MAX_HORIZON_PIECEScxx . . $ `Descent3/terrain.h:53:9`!; t++) {
695 vectorcxx . . $ vector# *vec = &Terrain_skycxx . . $ Terrain_sky..horizon_vectorscxx . . $ terrain_sky#horizon_vectors.[t][i];
696
697 matrixcxx . . $ matrix# tempm;
698 vm_AnglesToMatrixcxx . . $ vm_AnglesToMatrix(654fa9e3c9c3be99).(&tempm, pitch, t * jump, 0);
699 vm_ScaleVectorcxx . . $ vm_ScaleVector(cfd0f9d897ccca3c).(vec, &tempm.fveccxx . . $ matrix#fvec., SKY_RADIUScxx . . $ `Descent3/terrain.cpp:44:9`! / 2);
700
701 vec->ycxx . . $ vector#y. -= MAX_TERRAIN_HEIGHTcxx . . $ `Descent3/terrain.h:46:9`!;
702 vec->ycxx . . $ vector#y. += (rad_diff / 4);
703 }
704 }
705
706 // Now figure out texture UVS
707 for (i = 0; i < 5; i++) {
708 float scalar = (float)i / 4.0;
709 int angle_increment = 65536 / MAX_HORIZON_PIECEScxx . . $ `Descent3/terrain.h:53:9`!;
710 for (t = 0; t < MAX_HORIZON_PIECEScxx . . $ `Descent3/terrain.h:53:9`!; t++) {
711 float cur_sin = FixSincxx . . $ FixSin(9a38df040a81ca35).(t * angle_increment) * scalar;
712 float cur_cos = FixCoscxx . . $ FixCos(9a38df040a81ca35).(t * angle_increment) * scalar;
713
714 cur_sin = (cur_sin + 1) / 2;
715 cur_cos = (cur_cos + 1) / 2;
716
717 Terrain_skycxx . . $ Terrain_sky..horizon_ucxx . . $ terrain_sky#horizon_u.[t][i] = cur_cos;
718 Terrain_skycxx . . $ Terrain_sky..horizon_vcxx . . $ terrain_sky#horizon_v.[t][i] = cur_sin;
719 }
720 }
721
722 int highcount = 0; // keep track of what stars are close to the top of the sphere
723 // don't draw too many of them
724 if (!randit)
725 return;
726
727 for (i = 0; i < MAX_STARScxx . . $ `Descent3/terrain.h:51:9`!; i++) {
728 vectorcxx . . $ vector# starvec;
729 matrixcxx . . $ matrix# tempm;
730 int p;
731 top = ((65536 / 4) * 3);
732 int highlimit = MAX_STARScxx . . $ `Descent3/terrain.h:51:9`! / 8;
733
734 p = ps_randcxx . . $ ps_rand(b126dc7c1de90089).() % (65336 / 4);
735
736 while (highcount > highlimit && p < 6000)
737 p = ps_randcxx . . $ ps_rand(b126dc7c1de90089).() % (65336 / 4);
738
739 if (p < 6000)
740 highcount++;
741
742 vm_AnglesToMatrixcxx . . $ vm_AnglesToMatrix(654fa9e3c9c3be99).(&tempm, (top + p) % 65336, (ps_randcxx . . $ ps_rand(b126dc7c1de90089).() * ps_randcxx . . $ ps_rand(b126dc7c1de90089).()) % 65536, 0);
743 vm_ScaleVectorcxx . . $ vm_ScaleVector(cfd0f9d897ccca3c).(&starvec, &tempm.fveccxx . . $ matrix#fvec., Terrain_skycxx . . $ Terrain_sky..radiuscxx . . $ terrain_sky#radius. * 500);
744 Terrain_skycxx . . $ Terrain_sky..star_vectorscxx . . $ terrain_sky#star_vectors.[i] =cxx . . $ vector#`operator=`(a48bc7e93a8dae5e). starvec;
745
746 // Now figure out the color of this star. The closer to horizon it is, the
747 // dimmer it is
748 float ynorm = starvec.ycxx . . $ vector#y. / (Terrain_skycxx . . $ Terrain_sky..radiuscxx . . $ terrain_sky#radius. * 500);
749
750 float color_norm = ynorm * 2;
751 color_norm = stdcxx . . $ std/::clampcxx . . $ std/clamp(3dbe0c69cb86ae06).(color_norm, 0.2f, 1.0f);
752 int color = ps_randcxx . . $ ps_rand(b126dc7c1de90089).() % 6;
753 int r, g, b;
754
755 if (color <= 2) {
756 r = 255;
757 g = 255;
758 b = 255;
759 } else if (color == 3) {
760 r = 255;
761 g = 200;
762 b = 200;
763 } else if (color == 4) {
764 r = 255;
765 g = 200;
766 b = 255;
767 } else {
768 r = 255;
769 g = 255;
770 b = 200;
771 }
772
773 r = ((1.0 - color_norm) * horizon_r) + (color_norm * r);
774 g = ((1.0 - color_norm) * horizon_g) + (color_norm * g);
775 b = ((1.0 - color_norm) * horizon_b) + (color_norm * b);
776
777 Terrain_skycxx . . $ Terrain_sky..star_colorcxx . . $ terrain_sky#star_color.[i] = GR_RGBcxx . . $ GR_RGB(530956271a9518a5).(r, g, b);
778 }
779
780 for (i = 0; i < MAX_SATELLITEScxx . . $ `Descent3/terrain.h:52:9`!; i++) {
781 vectorcxx . . $ vector# satellitevec;
782 matrixcxx . . $ matrix# tempm;
783
784 int p = ps_randcxx . . $ ps_rand(b126dc7c1de90089).() % (65336 / 8);
785 top = ((65536 / 4) * 3) + (4096); // don't do satellites that are straight up
786
787 vm_AnglesToMatrixcxx . . $ vm_AnglesToMatrix(654fa9e3c9c3be99).(&tempm, (top + p) % 65336, (ps_randcxx . . $ ps_rand(b126dc7c1de90089).() * ps_randcxx . . $ ps_rand(b126dc7c1de90089).()) % 65536, 0);
788 vm_ScaleVectorcxx . . $ vm_ScaleVector(cfd0f9d897ccca3c).(&satellitevec, &tempm.fveccxx . . $ matrix#fvec., Terrain_skycxx . . $ Terrain_sky..radiuscxx . . $ terrain_sky#radius. * 3);
789 Terrain_skycxx . . $ Terrain_sky..satellite_vectorscxx . . $ terrain_sky#satellite_vectors.[i] =cxx . . $ vector#`operator=`(a48bc7e93a8dae5e). satellitevec;
790 Terrain_skycxx . . $ Terrain_sky..satellite_sizecxx . . $ terrain_sky#satellite_size.[i] = 500;
791 }
792 }
793
794 // Loads a pcx bitmap to be used as a height map
795 int LoadPCXTerraincxx . . $ LoadPCXTerrain(1ef8e6ec083aabb9).(char *filename) {
796 CFILEcxx . . $ CFILE# *infile;
797 int run = 0, i, total, j, n;
798 int16_t xmin, ymin, xmax, ymax;
799 int width, height;
800 uint8_tcxx . . $ uint8_t# buf;
801 uint8_tcxx . . $ uint8_t# *lando;
802
803 if ((infile = cfopencxx . . $ cfopen(7c7b94e455f1ae56).(filenamecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d)., "rb")) == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
804 return (0);
805
806 cf_ReadIntcxx . . $ cf_ReadInt(d60d6f5e30f0c96a).(infile);
807 xmin = cf_ReadShortcxx . . $ cf_ReadShort(30b00389b433b379).(infile);
808 ymin = cf_ReadShortcxx . . $ cf_ReadShort(30b00389b433b379).(infile);
809 xmax = cf_ReadShortcxx . . $ cf_ReadShort(30b00389b433b379).(infile);
810 ymax = cf_ReadShortcxx . . $ cf_ReadShort(30b00389b433b379).(infile);
811
812 for (n = 0; n < 116; n++)
813 cf_ReadBytecxx . . $ cf_ReadByte(dcbbf0b0e13758ec).(infile);
814
815 width = 1 + xmax - xmin;
816 height = 1 + ymax - ymin;
817
818 total = width * height;
819
820 lando = (uint8_tcxx . . $ uint8_t# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(total);
821
822 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Heightmap is %d x %d\n", width, height);
823
824 while (run < total) {
825 buf = cf_ReadBytecxx . . $ cf_ReadByte(dcbbf0b0e13758ec).(infile);
826 if (buf >= 192) {
827 uint8_tcxx . . $ uint8_t# tb = 0;
828 tb = cf_ReadBytecxx . . $ cf_ReadByte(dcbbf0b0e13758ec).(infile);
829 for (i = 0; i < (buf - 192); i++, run++)
830 lando[run] = tb;
831 } else {
832 lando[run] = buf;
833 run++;
834 }
835 }
836
837 cfclosecxx . . $ cfclose(3639e799710acb68).(infile);
838
839 for (i = 0; i < TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!; i++)
840 for (j = 0; j < TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!; j++) {
841 n = (int)lando[((i % height) * width) + (j % width)];
842
843 Terrain_segcxx . . $ Terrain_seg.[((TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! - 1) - i) * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + j].yposcxx . . $ terrain_segment#ypos. = n;
844 }
845
846 mem_freecxx . . $ `mem/mem.h:80:9`!(lando);
847 BuildMinMaxTerraincxx . . $ BuildMinMaxTerrain(49f6e7a06ebc5aa8).();
848 BuildTerrainNormalscxx . . $ BuildTerrainNormals(49f6e7a06ebc5aa8).();
849 GenerateTerrainLightcxx . . $ GenerateTerrainLight(49f6e7a06ebc5aa8).();
850
851 #if (defined(EDITOR) || defined(NEWEDITOR))
852 memset(TerrainSelected, 0, TERRAIN_WIDTH * TERRAIN_DEPTH);
853 Num_terrain_selected = 0;
854 World_changed = 1;
855 #endif
856
857 return (1);
858 }
859
860 // Called whenever a new level is initted
861 void ResetTerraincxx . . $ ResetTerrain(d4f767463ce0a6b3).(int force) {
862 int i, t;
863 int tex_index = FindTextureNamecxx . . $ FindTextureName(5c4306d8553b3696).("RainbowTexture");
864
865 if (tex_index < 0)
866 tex_index = 4; // stuff some random value
867
868 for (i = 0; i < TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!; i++) {
869 for (t = 0; t < TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!; t++) {
870 #if (!defined(RELEASE) || defined(NEWEDITOR))
871 Terrain_seg_render_objscxx . . $ Terrain_seg_render_objs.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t] = -1;
872 #endif
873 Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t].objectscxx . . $ terrain_segment#objects. = -1;
874 Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t].flagscxx . . $ terrain_segment#flags. = 0;
875 Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t].lm_quadcxx . . $ terrain_segment#lm_quad. = ((i / 128) * 2) + (t / 128);
876 Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t].texseg_indexcxx . . $ terrain_segment#texseg_index. = ((i >> 3) * TERRAIN_TEX_WIDTHcxx . . $ `Descent3/terrain.h:34:9`!) + (t >> 3);
877
878 Terrain_dynamic_tablecxx . . $ Terrain_dynamic_table.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t] = 0xFF;
879 }
880 }
881
882 for (i = 0; i < TERRAIN_TEX_DEPTHcxx . . $ `Descent3/terrain.h:35:9`!; i++) {
883 for (t = 0; t < TERRAIN_TEX_WIDTHcxx . . $ `Descent3/terrain.h:34:9`!; t++) {
884 int s = i * TERRAIN_TEX_WIDTHcxx . . $ `Descent3/terrain.h:34:9`! + t;
885 Terrain_tex_segcxx . . $ Terrain_tex_seg.[s].tex_indexcxx . . $ terrain_tex_segment#tex_index. = tex_index;
886 Terrain_tex_segcxx . . $ Terrain_tex_seg.[s].rotationcxx . . $ terrain_tex_segment#rotation. = (1 << 4);
887 }
888 }
889
890 if (force) {
891 Terrain_checksumcxx . . $ Terrain_checksum. = -1;
892
893 for (i = 0; i < TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!; i++) {
894 for (t = 0; t < TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!; t++) {
895 Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t].ycxx . . $ terrain_segment#y. = 0;
896 Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t].yposcxx . . $ terrain_segment#ypos. = 0;
897 }
898 }
899
900 for (i = 0; i < 7; i++) {
901 int size = 1 << i;
902 memset(Terrain_min_height_intcxx . . $ Terrain_min_height_int.[i], 0, size * size);
903 memset(Terrain_max_height_intcxx . . $ Terrain_max_height_int.[i], 0, size * size);
904 }
905
906 if (!Dedicated_servercxx . . $ Dedicated_server.) {
907 for (i = 0; i < MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1; i++) {
908 int w = TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! >> ((MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1) - i);
909 int h = TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`! >> ((MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1) - i);
910
911 memset(TerrainDeltaBlockscxx . . $ TerrainDeltaBlocks.[i], 0, w * h * sizeof(float));
912 }
913 }
914 }
915
916 BuildTerrainNormalscxx . . $ BuildTerrainNormals(49f6e7a06ebc5aa8).();
917
918 for (i = 0; i < MAX_SATELLITEScxx . . $ `Descent3/terrain.h:52:9`!; i++) {
919 Terrain_skycxx . . $ Terrain_sky..satellite_texturecxx . . $ terrain_sky#satellite_texture.[i] = 111;
920 Terrain_skycxx . . $ Terrain_sky..satellite_flagscxx . . $ terrain_sky#satellite_flags.[i] = 0;
921 }
922
923 GenerateTerrainLightcxx . . $ GenerateTerrainLight(49f6e7a06ebc5aa8).();
924
925 #if (defined(EDITOR) || defined(NEWEDITOR))
926 memset(TerrainSelected, 0, TERRAIN_WIDTH * TERRAIN_DEPTH);
927 #endif
928
929 memset(TerrainJoinMapcxx . . $ TerrainJoinMap., 0, TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! * TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!);
930
931 Terrain_skycxx . . $ Terrain_sky..damage_per_secondcxx . . $ terrain_sky#damage_per_second. = 0;
932 Terrain_skycxx . . $ Terrain_sky..fog_scalarcxx . . $ terrain_sky#fog_scalar. = .85f;
933 SetupSkyTexturecxx . . $ SetupSkyTexture(49f6e7a06ebc5aa8).();
934 ResetWeathercxx . . $ ResetWeather(49f6e7a06ebc5aa8).();
935 }
936
937 // Takes our 1st satellite and fills in the appropriate values in the lightsource vector
938 void GenerateLightSourcecxx . . $ GenerateLightSource(49f6e7a06ebc5aa8).() {
939 Terrain_skycxx . . $ Terrain_sky..lightsourcecxx . . $ terrain_sky#lightsource..xcxx . . $ vector#x. = FixCoscxx . . $ FixCos(9a38df040a81ca35).(Terrain_skycxx . . $ Terrain_sky..lightanglecxx . . $ terrain_sky#lightangle.);
940 Terrain_skycxx . . $ Terrain_sky..lightsourcecxx . . $ terrain_sky#lightsource..zcxx . . $ vector#z. = FixSincxx . . $ FixSin(9a38df040a81ca35).(Terrain_skycxx . . $ Terrain_sky..lightanglecxx . . $ terrain_sky#lightangle.);
941 }
942
943 void InitTerraincxx . . $ InitTerrain(49f6e7a06ebc5aa8).(void) {
944 int i, w, h, t;
945
946 // set sky texture to unused
947 Terrain_skycxx . . $ Terrain_sky..texturedcxx . . $ terrain_sky#textured. = 0;
948
949 // Setup stuff for rendering
950 if (!Dedicated_servercxx . . $ Dedicated_server.) {
951 Terrain_rotate_listcxx . . $ Terrain_rotate_list. = (uint16_tcxx . . $ uint16_t# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! * TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`! * sizeof(uint16_t));
952 ASSERTcxx . . $ `misc/pserror.h:246:9`!(Terrain_rotate_list);
953
954 World_point_buffercxx . . $ World_point_buffer. = (g3Pointcxx . . $ g3Point# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! * TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`! * sizeof(g3Point));
955 ASSERTcxx . . $ `misc/pserror.h:246:9`!(World_point_buffer);
956
957 // Allocate space for lod delta tree and unique texture IDs
958 for (i = 0; i < MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1; i++) {
959 w = TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! >> ((MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1) - i);
960 h = TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`! >> ((MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1) - i);
961
962 TerrainDeltaBlockscxx . . $ TerrainDeltaBlocks.[i] = (float *)mem_malloccxx . . $ `mem/mem.h:79:9`!(w * h * sizeof(float));
963 }
964 }
965
966 // Allocate space for lod normals
967
968 for (i = MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1; i < MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`!; i++) {
969 w = TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! >> ((MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1) - i);
970 h = TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`! >> ((MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1) - i);
971
972 TerrainNormalscxx . . $ TerrainNormals.[i] = (terrain_normalscxx . . $ terrain_normals# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(w * h * sizeof(terrain_normals));
973 memset(TerrainNormalscxx . . $ TerrainNormals.[i], 0, w * h * sizeof(terrain_normalscxx . . $ terrain_normals#));
974 }
975
976 // Allocate space for our min/max tables
977 for (i = 0; i < 7; i++) {
978 w = 1 << i;
979 h = 1 << i;
980
981 // Index 1 cuts the whole thing into 4ths, index 2 into 8ths, etc
982 Terrain_min_height_intcxx . . $ Terrain_min_height_int.[i] = (uint8_tcxx . . $ uint8_t# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(w * h * sizeof(uint8_t));
983 Terrain_max_height_intcxx . . $ Terrain_max_height_int.[i] = (uint8_tcxx . . $ uint8_t# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(w * h * sizeof(uint8_t));
984
985 ASSERTcxx . . $ `misc/pserror.h:246:9`!(Terrain_min_height_int[i] != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!);
986 ASSERTcxx . . $ `misc/pserror.h:246:9`!(Terrain_max_height_int[i] != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!);
987 }
988
989 Terrain_skycxx . . $ Terrain_sky..lightanglecxx . . $ terrain_sky#lightangle. = 0;
990 Terrain_skycxx . . $ Terrain_sky..num_satellitescxx . . $ terrain_sky#num_satellites. = 1;
991 Terrain_skycxx . . $ Terrain_sky..damage_per_secondcxx . . $ terrain_sky#damage_per_second. = 0;
992
993 SetupSkycxx . . $ SetupSky(20c5b41d67e83162).(SKY_RADIUScxx . . $ `Descent3/terrain.cpp:44:9`!, TF_STARScxx . . $ `Descent3/terrain.h:56:9`! | TF_SATELLITEScxx . . $ `Descent3/terrain.h:57:9`!, 1);
994 GenerateLightSourcecxx . . $ GenerateLightSource(49f6e7a06ebc5aa8).();
995
996 for (i = 0; i < 4; i++) {
997 TerrainLightmapscxx . . $ TerrainLightmaps.[i] = lm_AllocLightmapcxx . . $ lm_AllocLightmap(9b79fb6aee4c0440).(128, 128);
998 ASSERTcxx . . $ `misc/pserror.h:246:9`!(TerrainLightmaps[i] != BAD_LM_INDEXcxx . . $ `lib/lightmap.h:25:9`!);
999 GameLightmapscxx . . $ GameLightmaps.[TerrainLightmapscxx . . $ TerrainLightmaps.[i]].flagscxx . . $ bms_lightmap#flags. |= LF_WRAPcxx . . $ `lib/lightmap.h:30:9`!;
1000 }
1001
1002 for (i = 0; i < MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`!; i++) {
1003 int simplemul = 1 << ((MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1) - i);
1004 int answer;
1005
1006 TerrainEdgeJumpcxx . . $ TerrainEdgeJump.[i] = simplemul;
1007
1008 for (t = 0; t < 16; t++) {
1009 if (t == 0)
1010 answer = 1;
1011 else {
1012 if (t % simplemul == 0)
1013 answer = 1;
1014 else
1015 answer = 0;
1016 }
1017 TerrainEdgeTestcxx . . $ TerrainEdgeTest.[i][t] = answer;
1018 }
1019 }
1020
1021 // Setup dome textures
1022 Terrain_skycxx . . $ Terrain_sky..dome_texturecxx . . $ terrain_sky#dome_texture. = 0;
1023
1024 atexitcxx . . $ atexit(cc8c495369588262).(CloseTerraincxx . . $ CloseTerrain(49f6e7a06ebc5aa8).);
1025 }
1026
1027 void UpdateSingleTerrainLightmapcxx . . $ UpdateSingleTerrainLightmap(d4f767463ce0a6b3).(int which) {
1028 int w = lm_wcxx . . $ lm_w(7864480464b09eea).(TerrainLightmapscxx . . $ TerrainLightmaps.[which]);
1029 int i, t;
1030
1031 GameLightmapscxx . . $ GameLightmaps.[TerrainLightmapscxx . . $ TerrainLightmaps.[which]].flagscxx . . $ bms_lightmap#flags. |= LF_CHANGEDcxx . . $ `lib/lightmap.h:28:9`!;
1032
1033 int sx = (which % 2) * 128;
1034 int sz = (which / 2) * 128;
1035
1036 for (i = sz; i < sz + 128; i++) {
1037 for (t = sx; t < sx + 128; t++) {
1038 int tseg = i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t;
1039 terrain_segmentcxx . . $ terrain_segment# *tp = &Terrain_segcxx . . $ Terrain_seg.[tseg];
1040
1041 uint16_tcxx . . $ uint16_t# color = GR_RGB16cxx . . $ GR_RGB16(6461fafb79bad5b9).(tp->rcxx . . $ terrain_segment#r., tp->gcxx . . $ terrain_segment#g., tp->bcxx . . $ terrain_segment#b.);
1042 uint16_tcxx . . $ uint16_t# *data = lm_datacxx . . $ lm_data(2fbd6a760478ca0f).(TerrainLightmapscxx . . $ TerrainLightmaps.[which]);
1043
1044 int x = t % 128;
1045 int y = 127 - (i % 128);
1046
1047 data[y * w + x] = OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`! | color;
1048 }
1049 }
1050 }
1051
1052 // Generates lightmaps based on the info given by the .light field of each Terrain_seg
1053 void UpdateTerrainLightmapscxx . . $ UpdateTerrainLightmaps(49f6e7a06ebc5aa8).() {
1054 int i, t;
1055
1056 // First make the wraparounds work right
1057
1058 // lower-left strip
1059 for (i = 0; i < 128; i++) {
1060 Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!].rcxx . . $ terrain_segment#r. = Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + 128].rcxx . . $ terrain_segment#r.;
1061 Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!].gcxx . . $ terrain_segment#g. = Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + 128].gcxx . . $ terrain_segment#g.;
1062 Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!].bcxx . . $ terrain_segment#b. = Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + 128].bcxx . . $ terrain_segment#b.;
1063
1064 Terrain_segcxx . . $ Terrain_seg.[i].rcxx . . $ terrain_segment#r. = Terrain_segcxx . . $ Terrain_seg.[128 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + i].rcxx . . $ terrain_segment#r.;
1065 Terrain_segcxx . . $ Terrain_seg.[i].gcxx . . $ terrain_segment#g. = Terrain_segcxx . . $ Terrain_seg.[128 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + i].gcxx . . $ terrain_segment#g.;
1066 Terrain_segcxx . . $ Terrain_seg.[i].bcxx . . $ terrain_segment#b. = Terrain_segcxx . . $ Terrain_seg.[128 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + i].bcxx . . $ terrain_segment#b.;
1067 }
1068
1069 // lower-right strip
1070 for (i = 0; i < 128; i++) {
1071 Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + 255].rcxx . . $ terrain_segment#r. = Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + 127].rcxx . . $ terrain_segment#r.;
1072 Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + 255].gcxx . . $ terrain_segment#g. = Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + 127].gcxx . . $ terrain_segment#g.;
1073 Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + 255].bcxx . . $ terrain_segment#b. = Terrain_segcxx . . $ Terrain_seg.[i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + 127].bcxx . . $ terrain_segment#b.;
1074
1075 Terrain_segcxx . . $ Terrain_seg.[i + 128].rcxx . . $ terrain_segment#r. = Terrain_segcxx . . $ Terrain_seg.[128 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + i + 128].rcxx . . $ terrain_segment#r.;
1076 Terrain_segcxx . . $ Terrain_seg.[i + 128].gcxx . . $ terrain_segment#g. = Terrain_segcxx . . $ Terrain_seg.[128 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + i + 128].gcxx . . $ terrain_segment#g.;
1077 Terrain_segcxx . . $ Terrain_seg.[i + 128].bcxx . . $ terrain_segment#b. = Terrain_segcxx . . $ Terrain_seg.[128 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + i + 128].bcxx . . $ terrain_segment#b.;
1078 }
1079
1080 // upper-left strip
1081 for (i = 0; i < 128; i++) {
1082 Terrain_segcxx . . $ Terrain_seg.[(i + 128) * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!].rcxx . . $ terrain_segment#r. = Terrain_segcxx . . $ Terrain_seg.[(i + 128) * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + 128].rcxx . . $ terrain_segment#r.;
1083 Terrain_segcxx . . $ Terrain_seg.[(i + 128) * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!].gcxx . . $ terrain_segment#g. = Terrain_segcxx . . $ Terrain_seg.[(i + 128) * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + 128].gcxx . . $ terrain_segment#g.;
1084 Terrain_segcxx . . $ Terrain_seg.[(i + 128) * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!].bcxx . . $ terrain_segment#b. = Terrain_segcxx . . $ Terrain_seg.[(i + 128) * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + 128].bcxx . . $ terrain_segment#b.;
1085
1086 Terrain_segcxx . . $ Terrain_seg.[255 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + i].rcxx . . $ terrain_segment#r. = Terrain_segcxx . . $ Terrain_seg.[127 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + i].rcxx . . $ terrain_segment#r.;
1087 Terrain_segcxx . . $ Terrain_seg.[255 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + i].gcxx . . $ terrain_segment#g. = Terrain_segcxx . . $ Terrain_seg.[127 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + i].gcxx . . $ terrain_segment#g.;
1088 Terrain_segcxx . . $ Terrain_seg.[255 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + i].bcxx . . $ terrain_segment#b. = Terrain_segcxx . . $ Terrain_seg.[127 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + i].bcxx . . $ terrain_segment#b.;
1089 }
1090
1091 // upper-right strip
1092 for (i = 0; i < 128; i++) {
1093 Terrain_segcxx . . $ Terrain_seg.[(i + 128) * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + 255].rcxx . . $ terrain_segment#r. = Terrain_segcxx . . $ Terrain_seg.[(i + 128) * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + 127].rcxx . . $ terrain_segment#r.;
1094 Terrain_segcxx . . $ Terrain_seg.[(i + 128) * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + 255].gcxx . . $ terrain_segment#g. = Terrain_segcxx . . $ Terrain_seg.[(i + 128) * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + 127].gcxx . . $ terrain_segment#g.;
1095 Terrain_segcxx . . $ Terrain_seg.[(i + 128) * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + 255].bcxx . . $ terrain_segment#b. = Terrain_segcxx . . $ Terrain_seg.[(i + 128) * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + 127].bcxx . . $ terrain_segment#b.;
1096
1097 Terrain_segcxx . . $ Terrain_seg.[255 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + i + 128].rcxx . . $ terrain_segment#r. = Terrain_segcxx . . $ Terrain_seg.[127 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + i + 128].rcxx . . $ terrain_segment#r.;
1098 Terrain_segcxx . . $ Terrain_seg.[255 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + i + 128].gcxx . . $ terrain_segment#g. = Terrain_segcxx . . $ Terrain_seg.[127 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + i + 128].gcxx . . $ terrain_segment#g.;
1099 Terrain_segcxx . . $ Terrain_seg.[255 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + i + 128].bcxx . . $ terrain_segment#b. = Terrain_segcxx . . $ Terrain_seg.[127 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + i + 128].bcxx . . $ terrain_segment#b.;
1100 }
1101
1102 int w = lm_wcxx . . $ lm_w(7864480464b09eea).(TerrainLightmapscxx . . $ TerrainLightmaps.[0]);
1103
1104 for (i = 0; i < TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!; i++) {
1105 for (t = 0; t < TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!; t++) {
1106 int tseg = i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t;
1107 terrain_segmentcxx . . $ terrain_segment# *tp = &Terrain_segcxx . . $ Terrain_seg.[tseg];
1108 int x = t % 128;
1109 int y = 127 - (i % 128);
1110 int which = ((i / 128) * 2) + (t / 128);
1111
1112 uint16_tcxx . . $ uint16_t# color = GR_RGB16cxx . . $ GR_RGB16(6461fafb79bad5b9).(tp->rcxx . . $ terrain_segment#r., tp->gcxx . . $ terrain_segment#g., tp->bcxx . . $ terrain_segment#b.);
1113 uint16_tcxx . . $ uint16_t# *data = lm_datacxx . . $ lm_data(2fbd6a760478ca0f).(TerrainLightmapscxx . . $ TerrainLightmaps.[which]);
1114
1115 data[y * w + x] = OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`! | color;
1116 }
1117 }
1118
1119 for (i = 0; i < 4; i++) {
1120 GameLightmapscxx . . $ GameLightmaps.[TerrainLightmapscxx . . $ TerrainLightmaps.[i]].flagscxx . . $ bms_lightmap#flags. |= LF_CHANGEDcxx . . $ `lib/lightmap.h:28:9`!;
1121 GameLightmapscxx . . $ GameLightmaps.[TerrainLightmapscxx . . $ TerrainLightmaps.[i]].flagscxx . . $ bms_lightmap#flags. &= ~LF_LIMITScxx . . $ `lib/lightmap.h:29:9`!;
1122 }
1123 }
1124
1125 // Builds the surface normal for terrain segment n
1126 void BuildNormalForTerrainSegmentcxx . . $ BuildNormalForTerrainSegment(d4f767463ce0a6b3).(int n) {
1127 int i, t;
1128
1129 vectorcxx . . $ vector# a, b, c;
1130
1131 if (n < 0 || n >= (TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! - 1) * (TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`! - 1))
1132 return;
1133
1134 i = n / TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!;
1135 t = n % TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!;
1136
1137 a.xcxx . . $ vector#x. = t * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
1138 a.ycxx . . $ vector#y. = Terrain_segcxx . . $ Terrain_seg.[(i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!) + (t)].ycxx . . $ terrain_segment#y.;
1139 a.zcxx . . $ vector#z. = i * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
1140
1141 b.xcxx . . $ vector#x. = t * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
1142 b.ycxx . . $ vector#y. = Terrain_segcxx . . $ Terrain_seg.[(i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!) + (t + TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!)].ycxx . . $ terrain_segment#y.;
1143 b.zcxx . . $ vector#z. = (i + 1) * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
1144
1145 c.xcxx . . $ vector#x. = (t + 1) * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
1146 c.ycxx . . $ vector#y. = Terrain_segcxx . . $ Terrain_seg.[(i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!) + (t + TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + 1)].ycxx . . $ terrain_segment#y.;
1147 c.zcxx . . $ vector#z. = (i + 1) * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
1148
1149 vm_GetNormalcxx . . $ vm_GetNormal(f84d76fdbff5e570).(&TerrainNormalscxx . . $ TerrainNormals.[MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1][i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t].normal1cxx . . $ terrain_normals#normal1., &a, &b, &c);
1150
1151 a.xcxx . . $ vector#x. = t * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
1152 a.ycxx . . $ vector#y. = Terrain_segcxx . . $ Terrain_seg.[(i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!) + (t)].ycxx . . $ terrain_segment#y.;
1153 a.zcxx . . $ vector#z. = i * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
1154
1155 b.xcxx . . $ vector#x. = (t + 1) * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
1156 b.ycxx . . $ vector#y. = Terrain_segcxx . . $ Terrain_seg.[(i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!) + (t + TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + 1)].ycxx . . $ terrain_segment#y.;
1157 b.zcxx . . $ vector#z. = (i + 1) * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
1158
1159 c.xcxx . . $ vector#x. = (t + 1) * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
1160 c.ycxx . . $ vector#y. = Terrain_segcxx . . $ Terrain_seg.[(i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!) + (t + 1)].ycxx . . $ terrain_segment#y.;
1161 c.zcxx . . $ vector#z. = (i)*TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!;
1162
1163 vm_GetNormalcxx . . $ vm_GetNormal(f84d76fdbff5e570).(&TerrainNormalscxx . . $ TerrainNormals.[MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1][i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t].normal2cxx . . $ terrain_normals#normal2., &a, &b, &c);
1164 }
1165
1166 // Builds the vertex normal for terrain segment n
1167 void BuildLightingNormalForSegmentcxx . . $ BuildLightingNormalForSegment(d4f767463ce0a6b3).(int n) {
1168 int i, t, hback, vback;
1169 vectorcxx . . $ vector# temp;
1170
1171 if (n < 0 || n >= (TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! - 1) * (TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`! - 1))
1172 return;
1173
1174 i = n / TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!;
1175 t = n % TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!;
1176
1177 if (i == 0)
1178 vback = TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`! - 1;
1179 else
1180 vback = i - 1;
1181
1182 if (t == 0)
1183 hback = TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! - 1;
1184 else
1185 hback = t - 1;
1186
1187 vm_MakeZerocxx . . $ vm_MakeZero(ec8cf6451c36d470).(&temp);
1188
1189 vm_AddVectorscxx . . $ vm_AddVectors(af83aca25ba5b41c).(&temp, &temp, &TerrainNormalscxx . . $ TerrainNormals.[MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1][i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + hback].normal2cxx . . $ terrain_normals#normal2.);
1190 vm_AddVectorscxx . . $ vm_AddVectors(af83aca25ba5b41c).(&temp, &temp, &TerrainNormalscxx . . $ TerrainNormals.[MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1][i * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t].normal2cxx . . $ terrain_normals#normal2.);
1191 vm_AddVectorscxx . . $ vm_AddVectors(af83aca25ba5b41c).(&temp, &temp, &TerrainNormalscxx . . $ TerrainNormals.[MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1][(vback)*TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + hback].normal1cxx . . $ terrain_normals#normal1.);
1192 vm_AddVectorscxx . . $ vm_AddVectors(af83aca25ba5b41c).(&temp, &temp, &TerrainNormalscxx . . $ TerrainNormals.[MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1][(vback)*TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + t].normal2cxx . . $ terrain_normals#normal2.);
1193
1194 vm_AverageVectorcxx . . $ vm_AverageVector(86b7faebfcd459cf).(&temp, 4);
1195 // vm_NormalizeVectorFast (&temp);
1196 }