| 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 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/TerrainSearch.cpp $ |
| 21 | * $Revision: 56 $ |
| 22 | * $Date: 12/27/99 7:48a $ |
| 23 | * $Author: Gwar $ |
| 24 | * |
| 25 | * |
| 26 | * |
| 27 | * $Log: /DescentIII/Main/TerrainSearch.cpp $ |
| 28 | * |
| 29 | * 56 12/27/99 7:48a Gwar |
| 30 | * added NEWEDITOR #ifdefs |
| 31 | * |
| 32 | * 55 10/12/99 10:19a Gwar |
| 33 | * adding terrain support to NEWEDITOR |
| 34 | * |
| 35 | * 54 5/13/99 3:42p Ardussi |
| 36 | * changes for compiling on the Mac |
| 37 | * |
| 38 | * 53 4/27/99 3:38p Jason |
| 39 | * fixed occlusion bug |
| 40 | * |
| 41 | * 52 4/16/99 12:37a Matt |
| 42 | * Made Windows & Linux versions use the same qsort calls. |
| 43 | * |
| 44 | * 51 4/15/99 1:43a Jeff |
| 45 | * changes for linux compile |
| 46 | * |
| 47 | * 50 4/14/99 3:57a Jeff |
| 48 | * fixed case mismatch in #includes |
| 49 | * |
| 50 | * 49 4/12/99 3:04p Jason |
| 51 | * changes for low memory |
| 52 | * |
| 53 | * 48 3/04/99 6:12p Jason |
| 54 | * fixed bug with terrain lod |
| 55 | * |
| 56 | * 47 3/04/99 4:53p Jason |
| 57 | * added LODOffs |
| 58 | * |
| 59 | * 46 2/06/99 10:00p Jason |
| 60 | * fixed bug with last rev |
| 61 | * |
| 62 | * 45 2/06/99 7:55p Jason |
| 63 | * Misc speedups |
| 64 | * |
| 65 | * 44 1/20/99 10:50a Jason |
| 66 | * added new terrain |
| 67 | * |
| 68 | * 43 9/30/98 8:05p Jason |
| 69 | * Don't do occlusion test if inside |
| 70 | * |
| 71 | * 42 9/29/98 10:49a Jason |
| 72 | * fixed invisible terrain problelm |
| 73 | * |
| 74 | * 41 9/25/98 9:25p Jason |
| 75 | * did some graphics optimizations |
| 76 | * |
| 77 | * 40 8/19/98 2:19p Jeff |
| 78 | * moved detail globals to a struct |
| 79 | * |
| 80 | * 39 6/15/98 12:10p Jason |
| 81 | * made SearchQuadTree intelligently bail if we run out of cell buffers |
| 82 | * |
| 83 | * 38 6/04/98 6:45p Jason |
| 84 | * made objects use the terrain occlusion system |
| 85 | * |
| 86 | * 37 6/04/98 6:17p Jason |
| 87 | * added terrain occlusion system |
| 88 | * |
| 89 | * 36 5/14/98 12:56p Jason |
| 90 | * changes to help lower memory usage |
| 91 | * |
| 92 | * 35 4/30/98 6:45p Jason |
| 93 | * more changes for weather |
| 94 | * |
| 95 | * 34 4/27/98 1:15p Jason |
| 96 | * made lod engine use current fov |
| 97 | * |
| 98 | * 33 4/15/98 8:39p Jason |
| 99 | * inlined some functions |
| 100 | * |
| 101 | * 32 3/17/98 5:02p Jason |
| 102 | * sped up rendering the terrain from the mine by a large amount |
| 103 | * |
| 104 | * 31 2/04/98 6:09p Matt |
| 105 | * Changed object room number to indicate a terrain cell via a flag. Got |
| 106 | * rid of the object flag which used to indicate terrain. |
| 107 | * |
| 108 | * 30 1/30/98 12:12p Jason |
| 109 | * fixed LOD bug. This gives us twice the framerate in hilly areas!!! |
| 110 | * |
| 111 | * 29 1/12/98 6:01p Jason |
| 112 | * fixed memory corruption bug |
| 113 | * |
| 114 | * 28 1/12/98 3:34p Jason |
| 115 | * sped up indoor rendering by clipping faces against portals |
| 116 | * |
| 117 | * 27 1/02/98 7:06p Jason |
| 118 | * fixed mprintf |
| 119 | * |
| 120 | * 26 10/10/97 6:31p Jason |
| 121 | * added extra level of detail level |
| 122 | * |
| 123 | * 25 10/03/97 1:17p Jason |
| 124 | * tweaked to get more speed |
| 125 | * |
| 126 | * 24 10/02/97 6:45p Jason |
| 127 | * optimized terrain rotation |
| 128 | * |
| 129 | * 23 9/19/97 1:02p Chris |
| 130 | * Better big object support |
| 131 | * |
| 132 | * 22 9/17/97 6:29p Jason |
| 133 | * took out qsorting |
| 134 | * |
| 135 | * 21 9/15/97 9:09p Chris |
| 136 | * Make invalid locations for GetColTerrainSegFromPos link to zero and not |
| 137 | * error with a -1 |
| 138 | * |
| 139 | * 20 9/15/97 5:35p Jason |
| 140 | * took out tracing drops |
| 141 | * |
| 142 | * 19 9/12/97 6:36p Chris |
| 143 | * Added collision terrain segment support |
| 144 | * Added some LARGE OBJECT collision support |
| 145 | * |
| 146 | * 18 9/02/97 10:47a Jason |
| 147 | * use separate variables for game and editor LOD engine status |
| 148 | * |
| 149 | * 17 8/21/97 5:15p Samir |
| 150 | * Put some ifdef EDITOR stuff around Drop_seg and Tracing_drop |
| 151 | * references. |
| 152 | * |
| 153 | * 16 8/20/97 6:18p Jason |
| 154 | * fixed memory corruption bug |
| 155 | * |
| 156 | * 15 8/07/97 3:19p Jason |
| 157 | * replaced old terrain tmap system with new one |
| 158 | * |
| 159 | * 14 8/06/97 11:43a Jason |
| 160 | * made lightmaps work correctly in the terrain |
| 161 | * |
| 162 | * 13 8/03/97 3:32p Jason |
| 163 | * sped up LodSortingFunction after VTune said this was a HotSpot |
| 164 | * |
| 165 | * 12 8/03/97 2:26p Jason |
| 166 | * tried to eke out a few more cycles per frame from the terrain engine |
| 167 | * |
| 168 | * 11 7/29/97 5:33p Jason |
| 169 | * cleaned up code |
| 170 | * |
| 171 | * 10 7/28/97 5:23p Jason |
| 172 | * added features to lod engine - namely dynamic texture generation |
| 173 | * |
| 174 | * 9 7/25/97 5:25p Jason |
| 175 | * fixed multiple bugs in terrain LOD engine |
| 176 | * |
| 177 | * 8 7/23/97 6:29p Jason |
| 178 | * took out annoying mprintf |
| 179 | * |
| 180 | * 7 7/23/97 6:27p Jason |
| 181 | * added code to support terrain simplification |
| 182 | * |
| 183 | * 6 7/18/97 7:58p Jason |
| 184 | * fixed small bug with dropped cells |
| 185 | * |
| 186 | * 5 7/16/97 4:07p Jason |
| 187 | * fixed all the remaining drop-out bugs |
| 188 | * |
| 189 | * 4 7/16/97 12:46p Jason |
| 190 | * fixed some bugs with terrain searching |
| 191 | * and freed up lots of memory |
| 192 | * |
| 193 | * 3 7/16/97 11:26a Samir |
| 194 | * |
| 195 | * 2 7/15/97 8:09p Jason |
| 196 | * made it faster! |
| 197 | * |
| 198 | * 23 6/25/97 1:55p Jason |
| 199 | * added Flat_terrain variaable for viewing terrain as a flat plane |
| 200 | * |
| 201 | * 22 6/24/97 4:47p Mark |
| 202 | * FROM JASON:Took out non-sorting |
| 203 | * |
| 204 | * 21 6/24/97 4:24p Jason |
| 205 | * changes for y only terrain position |
| 206 | * |
| 207 | * 20 6/24/97 12:49p Jason |
| 208 | * |
| 209 | * 19 5/21/97 12:29p Jason |
| 210 | * added the ability to draw terrain dots in mine view |
| 211 | * |
| 212 | * 18 5/11/97 1:31p Matt |
| 213 | * Added code to only render terrain that might be visible when terrain |
| 214 | * called from the mine renderer. |
| 215 | * |
| 216 | * $NoKeywords: $ |
| 217 | */ |
| 218 | |
| 219 | #include "terrain.h"cxx . . $ `<file>/Descent3/terrain.h`/ |
| 220 | #include "3d.h"cxx . . $ `<file>/lib/3d.h`/ |
| 221 | #include "mono.h"cxx . . $ `<file>/ddebug/mono.h`/ |
| 222 | #include "vecmat.h"cxx . . $ `<file>/lib/vecmat.h`/ |
| 223 | #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/ |
| 224 | #include "pstypes.h"cxx . . $ `<file>/lib/pstypes.h`/ |
| 225 | #include "descent.h"cxx . . $ `<file>/Descent3/descent.h`/ |
| 226 | #include "game.h"cxx . . $ `<file>/Descent3/game.h`/ |
| 227 | #include "gameloop.h"cxx . . $ `<file>/Descent3/gameloop.h`/ |
| 228 | #include <memory.h> |
| 229 | #include <stdlib.h> |
| 230 | #include "config.h"cxx . . $ `<file>/Descent3/config.h`/ |
| 231 | #include "dedicated_server.h"cxx . . $ `<file>/lib/dedicated_server.h`/ |
| 232 | |
| 233 | |
| 234 | static int EvaluateBlockcxx . . $ EvaluateBlock(2326284602b0bb2d).(int x, int z, int lod); |
| 235 | |
| 236 | uint16_tcxx . . $ uint16_t# TS_FrameCountcxx . . $ TS_FrameCount. = 0xFFFF; |
| 237 | |
| 238 | static int SearchQuadTreecxx . . $ SearchQuadTree(5de03e331eeba043).(int x1, int y1, int x2, int y2, int dir, int *ccount); |
| 239 | int GlobalTransCountcxx . . $ GlobalTransCount. = 0; |
| 240 | int TotalDepthcxx . . $ TotalDepth.; |
| 241 | |
| 242 | // LOD shutoff stuff |
| 243 | #define MAX_LODOFFScxx . . $ `Descent3/TerrainSearch.cpp:243:9`! 100 |
| 244 | static lodoffcxx . . $ lodoff# LODOffscxx . . $ LODOffs.[MAX_LODOFFScxx . . $ `Descent3/TerrainSearch.cpp:243:9`!]; |
| 245 | static int Num_lodoffscxx . . $ Num_lodoffs. = 0; |
| 246 | |
| 247 | // Render the terrain as flat? |
| 248 | uint8_tcxx . . $ uint8_t# Flat_terraincxx . . $ Flat_terrain. = 0; |
| 249 | |
| 250 | // Variables for LOD engine |
| 251 | static float ViewDistance1cxx . . $ ViewDistance1. = .68f, ViewDistance2cxx . . $ ViewDistance2. = 1.0f; |
| 252 | static float TS_Lambdacxx . . $ TS_Lambda., TS_SimplifyConditioncxx . . $ TS_SimplifyCondition.; |
| 253 | |
| 254 | static matrixcxx . . $ matrix# *TS_View_matrixcxx . . $ TS_View_matrix.; |
| 255 | static vectorcxx . . $ vector# *TS_View_positioncxx . . $ TS_View_position.; |
| 256 | |
| 257 | static vectorcxx . . $ vector# TS_PreRowscxx . . $ TS_PreRows.[TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!]; |
| 258 | static vectorcxx . . $ vector# TS_FVectorAddcxx . . $ TS_FVectorAdd., TS_RVectorAddcxx . . $ TS_RVectorAdd.; |
| 259 | |
| 260 | static uint8_tcxx . . $ uint8_t# Terrain_y_flagscxx . . $ Terrain_y_flags.[256]; |
| 261 | static vectorcxx . . $ vector# Terrain_y_cachecxx . . $ Terrain_y_cache.[256]; |
| 262 | |
| 263 | static uint16_tcxx . . $ uint16_t# LOD_sort_bucketcxx . . $ LOD_sort_bucket.[MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`!][MAX_CELLS_TO_RENDERcxx . . $ `Descent3/terrain.h:44:9`!]; |
| 264 | static uint16_tcxx . . $ uint16_t# LOD_sort_numcxx . . $ LOD_sort_num.[MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`!]; |
| 265 | |
| 266 | // Variable to determine if we're in editor or game |
| 267 | extern function_modecxx . . $ function_mode# View_modecxx . . $ View_mode.; |
| 268 | |
| 269 | static vectorcxx . . $ vector# TJoint_VectorAddZcxx . . $ TJoint_VectorAddZ.; |
| 270 | static vectorcxx . . $ vector# TJoint_VectorAddXcxx . . $ TJoint_VectorAddX.; |
| 271 | |
| 272 | // Since our terrain points increment in finite steps we can rotate 2 points (x,z) |
| 273 | // just add them to a base point to get the final rotated point |
| 274 | void PreRotateTerraincxx . . $ PreRotateTerrain(49f6e7a06ebc5aa8).() { |
| 275 | vectorcxx . . $ vector# rvec = {1 * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!, 0, 0}; |
| 276 | vectorcxx . . $ vector# fvec = {0, 0, 1 * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!}; |
| 277 | |
| 278 | vectorcxx . . $ vector# tj_rvec = {4, 0, 0}; |
| 279 | vectorcxx . . $ vector# tj_fvec = {0, 0, 4}; |
| 280 | |
| 281 | TS_FVectorAddcxx . . $ TS_FVectorAdd. =cxx . . $ vector#`operator=`(c0842353a20857d). fvec *cxx . . $ `operator*`(14b8f9ac5c1e7b85). *TS_View_matrixcxx . . $ TS_View_matrix.; |
| 282 | TS_RVectorAddcxx . . $ TS_RVectorAdd. =cxx . . $ vector#`operator=`(c0842353a20857d). rvec *cxx . . $ `operator*`(14b8f9ac5c1e7b85). *TS_View_matrixcxx . . $ TS_View_matrix.; |
| 283 | |
| 284 | vectorcxx . . $ vector# start_vec = {0.0f, 0.0f, 0.0f}; |
| 285 | vectorcxx . . $ vector# temp_vec = start_vec -cxx . . $ operator-(b77b703cd1e43e33). *TS_View_positioncxx . . $ TS_View_position.; |
| 286 | start_vec =cxx . . $ vector#`operator=`(c0842353a20857d). temp_vec *cxx . . $ `operator*`(14b8f9ac5c1e7b85). *TS_View_matrixcxx . . $ TS_View_matrix.; |
| 287 | |
| 288 | TS_PreRowscxx . . $ TS_PreRows.[0] =cxx . . $ vector#`operator=`(a48bc7e93a8dae5e). start_vec; |
| 289 | |
| 290 | int i; |
| 291 | for (i = 1; i < TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!; i++) { |
| 292 | TS_PreRowscxx . . $ TS_PreRows.[i] =cxx . . $ vector#`operator=`(c0842353a20857d). TS_PreRowscxx . . $ TS_PreRows.[i - 1] +cxx . . $ operator+(b77b703cd1e43e33). TS_FVectorAddcxx . . $ TS_FVectorAdd.; |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | static inline vectorcxx . . $ vector# *GetDYVectorcxx . . $ GetDYVector(2a00e65a2395ba15).(int h) { |
| 297 | vectorcxx . . $ vector# *dyp; |
| 298 | |
| 299 | dyp = &Terrain_y_cachecxx . . $ Terrain_y_cache.[h]; |
| 300 | |
| 301 | if (!Terrain_y_flagscxx . . $ Terrain_y_flags.[h]) { |
| 302 | vectorcxx . . $ vector# up_vector = {0, h * TERRAIN_HEIGHT_INCREMENTcxx . . $ `Descent3/terrain.h:47:9`!, 0}; |
| 303 | |
| 304 | *dyp =cxx . . $ vector#`operator=`(c0842353a20857d). up_vector *cxx . . $ `operator*`(14b8f9ac5c1e7b85). *TS_View_matrixcxx . . $ TS_View_matrix.; |
| 305 | |
| 306 | Terrain_y_flagscxx . . $ Terrain_y_flags.[h] = 1; |
| 307 | } |
| 308 | |
| 309 | return dyp; |
| 310 | } |
| 311 | |
| 312 | static inline void GetPreRotatedPointFastcxx . . $ GetPreRotatedPointFast(a38d76786f54323e).(vectorcxx . . $ vector# *dest, int x, int z, int yvalue) { |
| 313 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(yvalue >= 0 && yvalue <= 255); |
| 314 | |
| 315 | // If the terrain is supposed to be flat, bash this to zero |
| 316 | #ifdef EDITOR |
| 317 | if (Flat_terrain) { |
| 318 | yvalue = 0; |
| 319 | } |
| 320 | #endif |
| 321 | |
| 322 | *dest =cxx . . $ vector#`operator=`(a48bc7e93a8dae5e). TS_PreRowscxx . . $ TS_PreRows.[z]; |
| 323 | *dest +=cxx . . $ `operator+=`(801a8d6f7ab7bef9). TS_RVectorAddcxx . . $ TS_RVectorAdd. *cxx . . $ `operator*`(252247219a31502c). x; |
| 324 | *dest +=cxx . . $ `operator+=`(801a8d6f7ab7bef9). *GetDYVectorcxx . . $ GetDYVector(2a00e65a2395ba15).(yvalue); |
| 325 | } |
| 326 | |
| 327 | void GetPreRotatedPointcxx . . $ GetPreRotatedPoint(64ae893c5b75a9e3).(g3Pointcxx . . $ g3Point# *dest, int x, int z, int yvalue) { |
| 328 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(yvalue >= 0 && yvalue <= 255); |
| 329 | |
| 330 | // If the terrain is supposed to be flat, bash this to zero |
| 331 | #ifdef EDITOR |
| 332 | if (Flat_terrain) { |
| 333 | yvalue = 0; |
| 334 | } |
| 335 | #endif |
| 336 | |
| 337 | dest->p3_veccxx . . $ g3Point#p3_vec. =cxx . . $ vector#`operator=`(a48bc7e93a8dae5e). TS_PreRowscxx . . $ TS_PreRows.[z]; |
| 338 | dest->p3_veccxx . . $ g3Point#p3_vec. +=cxx . . $ `operator+=`(801a8d6f7ab7bef9). TS_RVectorAddcxx . . $ TS_RVectorAdd. *cxx . . $ `operator*`(252247219a31502c). x; |
| 339 | dest->p3_veccxx . . $ g3Point#p3_vec. +=cxx . . $ `operator+=`(801a8d6f7ab7bef9). *GetDYVectorcxx . . $ GetDYVector(2a00e65a2395ba15).(yvalue); |
| 340 | |
| 341 | // also store the unrotated point |
| 342 | dest->p3_flagscxx . . $ g3Point#p3_flags. |= PF_ORIGPOINTcxx . . $ `lib/3d.h:221:9`!; |
| 343 | dest->p3_vecPreRotcxx . . $ g3Point#p3_vecPreRot..xcxx . . $ vector#x. = TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`! * x; |
| 344 | dest->p3_vecPreRotcxx . . $ g3Point#p3_vecPreRot..ycxx . . $ vector#y. = TERRAIN_HEIGHT_INCREMENTcxx . . $ `Descent3/terrain.h:47:9`! * yvalue; |
| 345 | dest->p3_vecPreRotcxx . . $ g3Point#p3_vecPreRot..zcxx . . $ vector#z. = TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`! * z; |
| 346 | } |
| 347 | |
| 348 | // Gets a pre-rotated point that does not fall exactly on one of our 255 height values |
| 349 | void GetSpecialRotatedPointcxx . . $ GetSpecialRotatedPoint(2f08a9677e0d7483).(g3Pointcxx . . $ g3Point# *dest, int x, int z, float yvalue) { |
| 350 | if (yvalue < 0) |
| 351 | yvalue = 0; |
| 352 | if (yvalue > MAX_TERRAIN_HEIGHTcxx . . $ `Descent3/terrain.h:46:9`!) |
| 353 | yvalue = MAX_TERRAIN_HEIGHTcxx . . $ `Descent3/terrain.h:46:9`!; |
| 354 | |
| 355 | vectorcxx . . $ vector# up_vector = {0, yvalue, 0}; |
| 356 | vectorcxx . . $ vector# dyp = up_vector *cxx . . $ `operator*`(14b8f9ac5c1e7b85). *TS_View_matrixcxx . . $ TS_View_matrix.; |
| 357 | |
| 358 | dest->p3_veccxx . . $ g3Point#p3_vec. =cxx . . $ vector#`operator=`(a48bc7e93a8dae5e). TS_PreRowscxx . . $ TS_PreRows.[z]; |
| 359 | dest->p3_veccxx . . $ g3Point#p3_vec. +=cxx . . $ `operator+=`(801a8d6f7ab7bef9). TS_RVectorAddcxx . . $ TS_RVectorAdd. *cxx . . $ `operator*`(252247219a31502c). x; |
| 360 | dest->p3_veccxx . . $ g3Point#p3_vec. +=cxx . . $ `operator+=`(801a8d6f7ab7bef9). dyp; |
| 361 | |
| 362 | // also store the unrotated point |
| 363 | dest->p3_flagscxx . . $ g3Point#p3_flags. |= PF_ORIGPOINTcxx . . $ `lib/3d.h:221:9`!; |
| 364 | dest->p3_vecPreRotcxx . . $ g3Point#p3_vecPreRot..xcxx . . $ vector#x. = TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`! * x; |
| 365 | dest->p3_vecPreRotcxx . . $ g3Point#p3_vecPreRot..ycxx . . $ vector#y. = yvalue; |
| 366 | dest->p3_vecPreRotcxx . . $ g3Point#p3_vecPreRot..zcxx . . $ vector#z. = TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`! * z; |
| 367 | } |
| 368 | |
| 369 | void Terrain_start_framecxx . . $ Terrain_start_frame(bc315f98e1febb02).(vectorcxx . . $ vector# *eye, matrixcxx . . $ matrix# *view_orient) { |
| 370 | TS_View_positioncxx . . $ TS_View_position. = eye; |
| 371 | TS_View_matrixcxx . . $ TS_View_matrix. = view_orient; |
| 372 | |
| 373 | // Set up variables for LOD switching |
| 374 | int width, height; |
| 375 | rend_GetProjectionParameterscxx . . $ rend_GetProjectionParameters(ce8f7825f8908cfa).(&width, &height); |
| 376 | TS_Lambdacxx . . $ TS_Lambda. = (float)height / (2 * ViewDistance1cxx . . $ ViewDistance1. * Render_zoomcxx . . $ Render_zoom.); |
| 377 | |
| 378 | #ifndef NEWEDITOR |
| 379 | TS_SimplifyConditioncxx . . $ TS_SimplifyCondition. = Detail_settingscxx . . $ Detail_settings..Pixel_errorcxx . . $ tDetailSettings#Pixel_error. / (TS_Lambdacxx . . $ TS_Lambda. * ViewDistance2cxx . . $ ViewDistance2.); |
| 380 | #else |
| 381 | TS_SimplifyCondition = 10.0f / (TS_Lambda * ViewDistance2); |
| 382 | #endif |
| 383 | TS_SimplifyConditioncxx . . $ TS_SimplifyCondition. *= TS_SimplifyConditioncxx . . $ TS_SimplifyCondition.; |
| 384 | |
| 385 | // Increment TS_framecount before searching... |
| 386 | TS_FrameCountcxx . . $ TS_FrameCount.++; |
| 387 | |
| 388 | if (TS_FrameCountcxx . . $ TS_FrameCount. == 0) { |
| 389 | TS_FrameCountcxx . . $ TS_FrameCount. = 1; |
| 390 | } |
| 391 | |
| 392 | memset(Terrain_y_flagscxx . . $ Terrain_y_flags., 0, 256); |
| 393 | memset(LOD_sort_numcxx . . $ LOD_sort_num., 0, MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! * sizeof(uint16_tcxx . . $ uint16_t#)); |
| 394 | |
| 395 | PreRotateTerraincxx . . $ PreRotateTerrain(49f6e7a06ebc5aa8).(); |
| 396 | } |
| 397 | |
| 398 | // Sorts our visible terrain blocks by lod level. The lower resolution blocks |
| 399 | // go first - this prevents cracking |
| 400 | |
| 401 | int LodSortingFunctioncxx . . $ LodSortingFunction(d140d406bafa7f55).(const terrain_render_infocxx . . $ terrain_render_info# *a, terrain_render_infocxx . . $ terrain_render_info# *b) { return a->lodcxx . . $ terrain_render_info#lod. - b->lodcxx . . $ terrain_render_info#lod.; } |
| 402 | |
| 403 | void SortLodLevelscxx . . $ SortLodLevels(d4f767463ce0a6b3).(int count) { |
| 404 | qsortcxx . . $ qsort(ebb60b13a65e77d7).(Terrain_listcxx . . $ Terrain_list., count, sizeof(terrain_render_infocxx . . $ terrain_render_info#), (int (*)(const void *, const void *))LodSortingFunctioncxx . . $ LodSortingFunction(d140d406bafa7f55).); |
| 405 | } |
| 406 | // returns number of cells in visible terrain |
| 407 | int GetVisibleTerraincxx . . $ GetVisibleTerrain(ffb987d81e13bf99).(vectorcxx . . $ vector# *eye, matrixcxx . . $ matrix# *view_orient) { |
| 408 | int cellcount = 0; |
| 409 | int i, t, count; |
| 410 | |
| 411 | GlobalTransCountcxx . . $ GlobalTransCount. = 0; |
| 412 | TotalDepthcxx . . $ TotalDepth. = 0; |
| 413 | |
| 414 | Terrain_start_framecxx . . $ Terrain_start_frame(bc315f98e1febb02).(eye, view_orient); |
| 415 | |
| 416 | SearchQuadTreecxx . . $ SearchQuadTree(5de03e331eeba043).(0, 0, TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!, TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!, 0, &cellcount); |
| 417 | |
| 418 | // Make sure lower levels of detail come first |
| 419 | for (count = 0, i = 0; i < MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`!; i++) { |
| 420 | for (t = 0; t < LOD_sort_numcxx . . $ LOD_sort_num.[i]; t++, count++) { |
| 421 | Terrain_listcxx . . $ Terrain_list.[count].lodcxx . . $ terrain_render_info#lod. = i; |
| 422 | Terrain_listcxx . . $ Terrain_list.[count].segmentcxx . . $ terrain_render_info#segment. = LOD_sort_bucketcxx . . $ LOD_sort_bucket.[i][t]; |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | // Increment TS_framecount after searching because we share Terrain_rotate_list |
| 427 | // with the rendering code |
| 428 | TS_FrameCountcxx . . $ TS_FrameCount.++; |
| 429 | |
| 430 | if (TS_FrameCountcxx . . $ TS_FrameCount. == 0) |
| 431 | TS_FrameCountcxx . . $ TS_FrameCount. = 1; |
| 432 | |
| 433 | return cellcount; |
| 434 | } |
| 435 | |
| 436 | __inline void CheckCellOccupancycxx . . $ CheckCellOccupancy(cc54b1d7b8a59e9f).(int x, int y, int *ccount, uint8_tcxx . . $ uint8_t# lod) { |
| 437 | int n, simplemul, i; |
| 438 | |
| 439 | if (*ccount >= MAX_CELLS_TO_RENDERcxx . . $ `Descent3/terrain.h:44:9`!) { |
| 440 | mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Trying to render too many cells! Cell limit=%d\n", MAX_CELLS_TO_RENDER); |
| 441 | #ifndef NEWEDITOR |
| 442 | Detail_settingscxx . . $ Detail_settings..Terrain_render_distancecxx . . $ tDetailSettings#Terrain_render_distance. = 80.0 * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!; |
| 443 | #endif |
| 444 | return; |
| 445 | } |
| 446 | |
| 447 | n = y * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + x; |
| 448 | |
| 449 | if (Show_invisible_terraincxx . . $ Show_invisible_terrain. == 0 && lod == MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1 && Terrain_segcxx . . $ Terrain_seg.[n].flagscxx . . $ terrain_segment#flags. & TF_INVISIBLEcxx . . $ `Descent3/terrain.h:76:9`!) |
| 450 | return; |
| 451 | |
| 452 | (*ccount)++; |
| 453 | |
| 454 | // Fill in our presorter |
| 455 | LOD_sort_bucketcxx . . $ LOD_sort_bucket.[lod][LOD_sort_numcxx . . $ LOD_sort_num.[lod]] = n; |
| 456 | LOD_sort_numcxx . . $ LOD_sort_num.[lod]++; |
| 457 | |
| 458 | // Fill in the join map so we know what edges touch what edges |
| 459 | if (lod != MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1) { |
| 460 | simplemul = 1 << ((MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1) - lod); |
| 461 | |
| 462 | for (i = 0; i < simplemul; i++) { |
| 463 | // Fill bottom edge |
| 464 | TerrainJoinMapcxx . . $ TerrainJoinMap.[y * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + x + i] = lod; |
| 465 | |
| 466 | // Fill top edge |
| 467 | TerrainJoinMapcxx . . $ TerrainJoinMap.[(y + simplemul - 1) * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + x + i] = lod; |
| 468 | |
| 469 | // Fill left edge |
| 470 | TerrainJoinMapcxx . . $ TerrainJoinMap.[(y + i) * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + x] = lod; |
| 471 | |
| 472 | // Fill right edge |
| 473 | TerrainJoinMapcxx . . $ TerrainJoinMap.[(y + i) * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + x + (simplemul - 1)] = lod; |
| 474 | } |
| 475 | } else |
| 476 | TerrainJoinMapcxx . . $ TerrainJoinMap.[y * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + x] = lod; |
| 477 | } |
| 478 | |
| 479 | #ifdef EDITOR |
| 480 | extern int Tracing_drops, Drop_seg; |
| 481 | #endif |
| 482 | |
| 483 | #define PUSH_STACK_TREEcxx . . $ `Descent3/TerrainSearch.cpp:483:9`!(a1, b1, a2, b2, l) \ |
| 484 | { \ |
| 485 | stack_x1[si] = a1; \ |
| 486 | stack_y1[si] = b1; \ |
| 487 | stack_y2[si] = b2; \ |
| 488 | stack_x2[si] = a2; \ |
| 489 | stack_level[si] = l; \ |
| 490 | si++; \ |
| 491 | } |
| 492 | #define POP_STACK_TREEcxx . . $ `Descent3/TerrainSearch.cpp:492:9`!() \ |
| 493 | { \ |
| 494 | si--; \ |
| 495 | x1 = stack_x1[si]; \ |
| 496 | x2 = stack_x2[si]; \ |
| 497 | y1 = stack_y1[si]; \ |
| 498 | y2 = stack_y2[si]; \ |
| 499 | level = stack_level[si]; \ |
| 500 | } |
| 501 | |
| 502 | int SearchQuadTreecxx . . $ SearchQuadTree(5de03e331eeba043).(int x1, int y1, int x2, int y2, int dir, int *ccount) { |
| 503 | int n[4], x[4], z[4]; |
| 504 | int i, first; |
| 505 | int anded; |
| 506 | int answer; |
| 507 | int si = 0, level; |
| 508 | int stack_x1[200]; |
| 509 | int stack_y1[200]; |
| 510 | int stack_x2[200]; |
| 511 | int stack_y2[200]; |
| 512 | int stack_level[200]; |
| 513 | float testdist = VisibleTerrainZcxx . . $ VisibleTerrainZ.; |
| 514 | uint8_tcxx . . $ uint8_t# ymin_int[4], ymax_int[4]; |
| 515 | int close; |
| 516 | uint8_tcxx . . $ uint8_t# same_side; |
| 517 | uint8_tcxx . . $ uint8_t# check_portal = 0; |
| 518 | g3Pointcxx . . $ g3Point# *pnt; |
| 519 | int use_occlusion = 0; |
| 520 | int src_occlusion_index; |
| 521 | |
| 522 | if ((Terrain_checksumcxx . . $ Terrain_checksum. + 1) == Terrain_occlusion_checksumcxx . . $ Terrain_occlusion_checksum. && !Terrain_from_minecxx . . $ Terrain_from_mine.) { |
| 523 | use_occlusion = 1; |
| 524 | int oz = (Viewer_objectcxx . . $ Viewer_object.->poscxx . . $ object#pos..zcxx . . $ vector#z. / TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!) / OCCLUSION_SIZEcxx . . $ `Descent3/terrain.h:67:9`!; |
| 525 | int ox = (Viewer_objectcxx . . $ Viewer_object.->poscxx . . $ object#pos..xcxx . . $ vector#x. / TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!) / OCCLUSION_SIZEcxx . . $ `Descent3/terrain.h:67:9`!; |
| 526 | |
| 527 | if (oz < 0 || oz >= OCCLUSION_SIZEcxx . . $ `Descent3/terrain.h:67:9`! || ox < 0 || ox >= OCCLUSION_SIZEcxx . . $ `Descent3/terrain.h:67:9`!) |
| 528 | use_occlusion = 0; |
| 529 | |
| 530 | src_occlusion_index = oz * OCCLUSION_SIZEcxx . . $ `Descent3/terrain.h:67:9`! + ox; |
| 531 | } |
| 532 | |
| 533 | PUSH_STACK_TREEcxx . . $ `Descent3/TerrainSearch.cpp:483:9`!(x1, y1, x2, y2, 0); |
| 534 | |
| 535 | while (si > 0) { |
| 536 | TotalDepthcxx . . $ TotalDepth.++; |
| 537 | |
| 538 | POP_STACK_TREEcxx . . $ `Descent3/TerrainSearch.cpp:492:9`!(); |
| 539 | ASSERTcxx . . $ `misc/pserror.h:246:9`!((x2 - x1) == (y2 - y1)); |
| 540 | |
| 541 | if ((x2 - x1) == 16) { |
| 542 | if (use_occlusion) { |
| 543 | int dest_occlusion_index = ((y1 / OCCLUSION_SIZEcxx . . $ `Descent3/terrain.h:67:9`!) * OCCLUSION_SIZEcxx . . $ `Descent3/terrain.h:67:9`!); |
| 544 | dest_occlusion_index += x1 / OCCLUSION_SIZEcxx . . $ `Descent3/terrain.h:67:9`!; |
| 545 | |
| 546 | int occ_byte = dest_occlusion_index / 8; |
| 547 | int occ_bit = dest_occlusion_index % 8; |
| 548 | |
| 549 | if (!(Terrain_occlusion_mapcxx . . $ Terrain_occlusion_map.[src_occlusion_index][occ_byte] & (1 << occ_bit))) |
| 550 | continue; |
| 551 | } |
| 552 | check_portal = 1; |
| 553 | } |
| 554 | |
| 555 | else if ((x2 - x1) == 8) { |
| 556 | answer = EvaluateBlockcxx . . $ EvaluateBlock(2326284602b0bb2d).(x1, y1, MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 4); |
| 557 | if (answer == -1) |
| 558 | continue; |
| 559 | else if (answer == 1) { |
| 560 | CheckCellOccupancycxx . . $ CheckCellOccupancy(cc54b1d7b8a59e9f).(x1, y1, ccount, MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 4); |
| 561 | continue; |
| 562 | } |
| 563 | check_portal = 1; |
| 564 | } |
| 565 | |
| 566 | else if ((x2 - x1) == 4) { |
| 567 | answer = EvaluateBlockcxx . . $ EvaluateBlock(2326284602b0bb2d).(x1, y1, MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 3); |
| 568 | if (answer == -1) |
| 569 | continue; |
| 570 | else if (answer == 1) { |
| 571 | CheckCellOccupancycxx . . $ CheckCellOccupancy(cc54b1d7b8a59e9f).(x1, y1, ccount, MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 3); |
| 572 | continue; |
| 573 | } |
| 574 | check_portal = 0; |
| 575 | } |
| 576 | |
| 577 | else if ((x2 - x1) == 2) { |
| 578 | answer = EvaluateBlockcxx . . $ EvaluateBlock(2326284602b0bb2d).(x1, y1, MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 2); |
| 579 | if (answer == -1) |
| 580 | continue; |
| 581 | else if (answer == 1) { |
| 582 | CheckCellOccupancycxx . . $ CheckCellOccupancy(cc54b1d7b8a59e9f).(x1, y1, ccount, MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 2); |
| 583 | continue; |
| 584 | } |
| 585 | check_portal = 0; |
| 586 | } |
| 587 | |
| 588 | if ((x2 - x1) <= 2) { |
| 589 | CheckCellOccupancycxx . . $ CheckCellOccupancy(cc54b1d7b8a59e9f).(x1, y1, ccount, MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1); |
| 590 | CheckCellOccupancycxx . . $ CheckCellOccupancy(cc54b1d7b8a59e9f).(x1, y1 + 1, ccount, MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1); |
| 591 | CheckCellOccupancycxx . . $ CheckCellOccupancy(cc54b1d7b8a59e9f).(x1 + 1, y1 + 1, ccount, MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1); |
| 592 | CheckCellOccupancycxx . . $ CheckCellOccupancy(cc54b1d7b8a59e9f).(x1 + 1, y1, ccount, MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1); |
| 593 | |
| 594 | #if (defined(EDITOR) || defined(NEWEDITOR)) |
| 595 | if (*ccount >= MAX_CELLS_TO_RENDER) |
| 596 | return 0; |
| 597 | #endif |
| 598 | |
| 599 | check_portal = 0; |
| 600 | |
| 601 | continue; |
| 602 | } |
| 603 | |
| 604 | // Starts at lower left, goes clockwise |
| 605 | n[0] = y1 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + x1; |
| 606 | n[1] = y2 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + x1; |
| 607 | n[2] = y2 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + x2; |
| 608 | n[3] = y1 * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + x2; |
| 609 | |
| 610 | x[0] = x[1] = x1; |
| 611 | x[2] = x[3] = x2; |
| 612 | z[0] = z[3] = y1; |
| 613 | z[1] = z[2] = y2; |
| 614 | |
| 615 | if (x2 == TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!) { |
| 616 | x[2]--; |
| 617 | x[3]--; |
| 618 | |
| 619 | n[2]--; |
| 620 | n[3]--; |
| 621 | } |
| 622 | |
| 623 | if (y2 == TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!) { |
| 624 | z[1]--; |
| 625 | z[2]--; |
| 626 | |
| 627 | n[1] -= TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!; |
| 628 | n[2] -= TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!; |
| 629 | } |
| 630 | |
| 631 | close = 0; |
| 632 | first = 1; |
| 633 | |
| 634 | anded = 0xff; |
| 635 | same_side = 0xff; |
| 636 | uint8_tcxx . . $ uint8_t# portal_and = 0xff; |
| 637 | |
| 638 | for (i = 0; i < 4; i++) { |
| 639 | if (first) { |
| 640 | int lx = x[i] >> (8 - level); |
| 641 | int lz = z[i] >> (8 - level); |
| 642 | |
| 643 | int cell = (lz << level) + lx; |
| 644 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(level <= 6); |
| 645 | |
| 646 | ymin_int[i] = *(Terrain_min_height_intcxx . . $ Terrain_min_height_int.[level] + cell); |
| 647 | ymax_int[i] = *(Terrain_max_height_intcxx . . $ Terrain_max_height_int.[level] + cell); |
| 648 | first = 0; |
| 649 | } |
| 650 | |
| 651 | pnt = &World_point_buffercxx . . $ World_point_buffer.[n[i]]; |
| 652 | |
| 653 | // Do min height for region |
| 654 | GetPreRotatedPointFastcxx . . $ GetPreRotatedPointFast(a38d76786f54323e).(&pnt->p3_veccxx . . $ g3Point#p3_vec., x[i], z[i], ymin_int[0]); |
| 655 | |
| 656 | if (pnt->p3_veccxx . . $ g3Point#p3_vec..zcxx . . $ vector#z. >= 0) |
| 657 | same_side &= 1; |
| 658 | else |
| 659 | same_side &= 2; |
| 660 | |
| 661 | if ((fabscxx . . $ fabs(fbcf3211dfe1bfd1).(pnt->p3_veccxx . . $ g3Point#p3_vec..zcxx . . $ vector#z.) <= testdist)) |
| 662 | close = 1; |
| 663 | |
| 664 | anded &= g3_CodePointcxx . . $ g3_CodePoint(1c2cda054d3314c5).(pnt); |
| 665 | if (Check_terrain_portalcxx . . $ Check_terrain_portal. && check_portal) { |
| 666 | pnt->p3_flagscxx . . $ g3Point#p3_flags. &= ~PF_PROJECTEDcxx . . $ `lib/3d.h:214:9`!; |
| 667 | // Automatically flag the ones behind us as visible |
| 668 | if (pnt->p3_codescxx . . $ g3Point#p3_codes. & CC_BEHINDcxx . . $ `lib/3d.h:230:9`!) |
| 669 | check_portal = 0; |
| 670 | else { |
| 671 | g3_ProjectPointcxx . . $ g3_ProjectPoint(4c7ad40c64d4fb9c).(pnt); |
| 672 | portal_and &= CodeTerrainPointcxx . . $ CodeTerrainPoint(1c2cda054d3314c5).(pnt); |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | // Do max height for region |
| 677 | GetPreRotatedPointFastcxx . . $ GetPreRotatedPointFast(a38d76786f54323e).(&pnt->p3_veccxx . . $ g3Point#p3_vec., x[i], z[i], ymax_int[0]); |
| 678 | |
| 679 | if (pnt->p3_veccxx . . $ g3Point#p3_vec..zcxx . . $ vector#z. >= 0) |
| 680 | same_side &= 1; |
| 681 | else |
| 682 | same_side &= 2; |
| 683 | |
| 684 | if ((fabscxx . . $ fabs(fbcf3211dfe1bfd1).(pnt->p3_veccxx . . $ g3Point#p3_vec..zcxx . . $ vector#z.) <= testdist)) |
| 685 | close = 1; |
| 686 | |
| 687 | anded &= g3_CodePointcxx . . $ g3_CodePoint(1c2cda054d3314c5).(pnt); |
| 688 | |
| 689 | if (Check_terrain_portalcxx . . $ Check_terrain_portal. && check_portal) { |
| 690 | pnt->p3_flagscxx . . $ g3Point#p3_flags. &= ~PF_PROJECTEDcxx . . $ `lib/3d.h:214:9`!; |
| 691 | // Automatically flag the ones behind us as visible |
| 692 | if (pnt->p3_codescxx . . $ g3Point#p3_codes. & CC_BEHINDcxx . . $ `lib/3d.h:230:9`!) |
| 693 | check_portal = 0; |
| 694 | else { |
| 695 | g3_ProjectPointcxx . . $ g3_ProjectPoint(4c7ad40c64d4fb9c).(pnt); |
| 696 | portal_and &= CodeTerrainPointcxx . . $ CodeTerrainPoint(1c2cda054d3314c5).(pnt); |
| 697 | } |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | if ((!anded && close) || (!anded && !close && !same_side)) { |
| 702 | // Recurse into this quadtree |
| 703 | |
| 704 | // Check to see if this is in our portal window |
| 705 | if (Check_terrain_portalcxx . . $ Check_terrain_portal. && check_portal && portal_and) |
| 706 | continue; |
| 707 | |
| 708 | int midx = ((x2 - x1) / 2) + x1; |
| 709 | int midy = ((y2 - y1) / 2) + y1; |
| 710 | |
| 711 | PUSH_STACK_TREEcxx . . $ `Descent3/TerrainSearch.cpp:483:9`!(x1, midy, midx, y2, level + 1); |
| 712 | PUSH_STACK_TREEcxx . . $ `Descent3/TerrainSearch.cpp:483:9`!(midx, midy, x2, y2, level + 1); |
| 713 | PUSH_STACK_TREEcxx . . $ `Descent3/TerrainSearch.cpp:483:9`!(midx, y1, x2, midy, level + 1); |
| 714 | PUSH_STACK_TREEcxx . . $ `Descent3/TerrainSearch.cpp:483:9`!(x1, y1, midx, midy, level + 1); |
| 715 | } else { |
| 716 | /*#ifdef EDITOR |
| 717 | if (Tracing_drops) |
| 718 | { |
| 719 | int dx=Drop_seg%TERRAIN_WIDTH; |
| 720 | int dz=Drop_seg/TERRAIN_WIDTH; |
| 721 | |
| 722 | if (x1<=dx && dx<=x2 && y1<=dz && dz<=y2) |
| 723 | { |
| 724 | Tracing_drops=0; |
| 725 | Int3(); |
| 726 | } |
| 727 | |
| 728 | } |
| 729 | #endif*/ |
| 730 | } |
| 731 | } |
| 732 | return 0; |
| 733 | } |
| 734 | |
| 735 | // Given a position, returns the terrain segment that that position is in/over |
| 736 | // returns -1 if not over terrain |
| 737 | int GetTerrainCellFromPoscxx . . $ GetTerrainCellFromPos(177d9005acf670a0).(vectorcxx . . $ vector# *pos) { |
| 738 | int x = pos->xcxx . . $ vector#x. / TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!; |
| 739 | int z = pos->zcxx . . $ vector#z. / TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!; |
| 740 | |
| 741 | if (x < 0 || x >= TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! || z < 0 || z >= TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!) |
| 742 | return -1; |
| 743 | |
| 744 | return (z * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + x); |
| 745 | } |
| 746 | |
| 747 | int GetTerrainRoomFromPoscxx . . $ GetTerrainRoomFromPos(177d9005acf670a0).(vectorcxx . . $ vector# *pos) { return MAKE_ROOMNUMcxx . . $ `lib/object_external_struct.h:124:9`!(GetTerrainCellFromPos(pos)); } |
| 748 | |
| 749 | // Computes the center of the segment in x,z and also sets y touching the ground |
| 750 | void ComputeTerrainSegmentCentercxx . . $ ComputeTerrainSegmentCenter(86b7faebfcd459cf).(vectorcxx . . $ vector# *pos, int segnum) { |
| 751 | int segx = segnum % TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!; |
| 752 | int segz = segnum / TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!; |
| 753 | |
| 754 | pos->xcxx . . $ vector#x. = (segx * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!) + (TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`! / 2); |
| 755 | pos->zcxx . . $ vector#z. = (segz * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!) + (TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`! / 2); |
| 756 | |
| 757 | pos->ycxx . . $ vector#y. = GetTerrainGroundPointcxx . . $ GetTerrainGroundPoint(a0b9c8659ecc16b8).(pos); |
| 758 | } |
| 759 | |
| 760 | // Given an position, returns the terrain Y coord at that location |
| 761 | float GetTerrainGroundPointcxx . . $ GetTerrainGroundPoint(a0b9c8659ecc16b8).(vectorcxx . . $ vector# *pos, vectorcxx . . $ vector# *normal) { |
| 762 | float y; |
| 763 | vectorcxx . . $ vector# pnt, norm; |
| 764 | int t; |
| 765 | int x, z; |
| 766 | |
| 767 | x = pos->xcxx . . $ vector#x. / TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!; |
| 768 | z = pos->zcxx . . $ vector#z. / TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!; |
| 769 | |
| 770 | if (x < 0 || x >= TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! || z < 0 || z >= TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!) |
| 771 | return (0); |
| 772 | |
| 773 | t = z * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + x; |
| 774 | |
| 775 | pnt =cxx . . $ vector#`operator=`(a48bc7e93a8dae5e). *pos; |
| 776 | pnt.xcxx . . $ vector#x. -= (x * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!); |
| 777 | pnt.zcxx . . $ vector#z. -= (z * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!); |
| 778 | |
| 779 | if (pnt.xcxx . . $ vector#x. > pnt.zcxx . . $ vector#z.) |
| 780 | norm =cxx . . $ vector#`operator=`(a48bc7e93a8dae5e). TerrainNormalscxx . . $ TerrainNormals.[MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1][t].normal2cxx . . $ terrain_normals#normal2.; |
| 781 | else |
| 782 | norm =cxx . . $ vector#`operator=`(a48bc7e93a8dae5e). TerrainNormalscxx . . $ TerrainNormals.[MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1][t].normal1cxx . . $ terrain_normals#normal1.; |
| 783 | |
| 784 | // Do plane equation on x,z and then interpolate y |
| 785 | y = ((pnt.xcxx . . $ vector#x. * norm.xcxx . . $ vector#x.) + (pnt.zcxx . . $ vector#z. * norm.zcxx . . $ vector#z.)) / norm.ycxx . . $ vector#y.; |
| 786 | y = -y; |
| 787 | y += Terrain_segcxx . . $ Terrain_seg.[t].ycxx . . $ terrain_segment#y.; |
| 788 | |
| 789 | if (normal != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 790 | *normal =cxx . . $ vector#`operator=`(a48bc7e93a8dae5e). norm; |
| 791 | |
| 792 | return (y); |
| 793 | } |
| 794 | |
| 795 | int SimplifyVertexSlowcxx . . $ SimplifyVertexSlow(1df3af30621f6c78).(int x, int z, float delta) { |
| 796 | vectorcxx . . $ vector# *eye = TS_View_positioncxx . . $ TS_View_position.; |
| 797 | g3Pointcxx . . $ g3Point# p1, p2; |
| 798 | |
| 799 | p1.p3_codescxx . . $ g3Point#p3_codes. = 0; |
| 800 | GetPreRotatedPointcxx . . $ GetPreRotatedPoint(64ae893c5b75a9e3).(&p1, x, z, Terrain_segcxx . . $ Terrain_seg.[z * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + x].yposcxx . . $ terrain_segment#ypos.); |
| 801 | |
| 802 | p2.p3_codescxx . . $ g3Point#p3_codes. = 0; |
| 803 | GetSpecialRotatedPointcxx . . $ GetSpecialRotatedPoint(2f08a9677e0d7483).(&p2, x, z, Terrain_segcxx . . $ Terrain_seg.[z * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + x].ycxx . . $ terrain_segment#y. + delta); |
| 804 | |
| 805 | g3_ProjectPointcxx . . $ g3_ProjectPoint(4c7ad40c64d4fb9c).(&p1); |
| 806 | g3_ProjectPointcxx . . $ g3_ProjectPoint(4c7ad40c64d4fb9c).(&p2); |
| 807 | |
| 808 | float len = ((p1.p3_sxcxx . . $ g3Point#p3_sx. - p2.p3_sxcxx . . $ g3Point#p3_sx.) * (p1.p3_sxcxx . . $ g3Point#p3_sx. - p2.p3_sxcxx . . $ g3Point#p3_sx.)) + ((p1.p3_sycxx . . $ g3Point#p3_sy. - p2.p3_sycxx . . $ g3Point#p3_sy.) * (p1.p3_sycxx . . $ g3Point#p3_sy. - p2.p3_sycxx . . $ g3Point#p3_sy.)); |
| 809 | |
| 810 | #ifndef NEWEDITOR |
| 811 | if (len < (Detail_settingscxx . . $ Detail_settings..Pixel_errorcxx . . $ tDetailSettings#Pixel_error. * Detail_settingscxx . . $ Detail_settings..Pixel_errorcxx . . $ tDetailSettings#Pixel_error.)) |
| 812 | #else |
| 813 | if (len < (10.0f * 10.0f)) |
| 814 | #endif |
| 815 | return 1; |
| 816 | |
| 817 | return 0; |
| 818 | } |
| 819 | |
| 820 | int SimplifyVertexcxx . . $ SimplifyVertex(1df3af30621f6c78).(int x, int z, float delta) { |
| 821 | vectorcxx . . $ vector# *eye = TS_View_positioncxx . . $ TS_View_position.; |
| 822 | vectorcxx . . $ vector# vec; |
| 823 | float inner; |
| 824 | |
| 825 | vec.xcxx . . $ vector#x. = x * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!; |
| 826 | vec.zcxx . . $ vector#z. = z * TERRAIN_SIZEcxx . . $ `Descent3/terrain.h:33:9`!; |
| 827 | vec.ycxx . . $ vector#y. = Terrain_segcxx . . $ Terrain_seg.[z * TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! + x].ycxx . . $ terrain_segment#y.; |
| 828 | |
| 829 | float delta_squared = delta * delta; |
| 830 | float first_part, second_part; |
| 831 | |
| 832 | float ex_minus_vx_squared = (eye->xcxx . . $ vector#x. - vec.xcxx . . $ vector#x.) * (eye->xcxx . . $ vector#x. - vec.xcxx . . $ vector#x.); |
| 833 | float ez_minus_vz_squared = (eye->zcxx . . $ vector#z. - vec.zcxx . . $ vector#z.) * (eye->zcxx . . $ vector#z. - vec.zcxx . . $ vector#z.); |
| 834 | float ey_minus_vy_squared = (eye->ycxx . . $ vector#y. - vec.ycxx . . $ vector#y.) * (eye->ycxx . . $ vector#y. - vec.ycxx . . $ vector#y.); |
| 835 | |
| 836 | first_part = delta_squared * (ex_minus_vx_squared + ez_minus_vz_squared); |
| 837 | |
| 838 | inner = ex_minus_vx_squared + ez_minus_vz_squared + ey_minus_vy_squared; |
| 839 | |
| 840 | second_part = (TS_SimplifyConditioncxx . . $ TS_SimplifyCondition.) * (inner * inner); |
| 841 | |
| 842 | if (first_part <= second_part) |
| 843 | return 1; |
| 844 | |
| 845 | return 0; |
| 846 | } |
| 847 | |
| 848 | // Returns 1 if the given block (specified by the upper left corder x,z) lod can |
| 849 | // be simplified |
| 850 | // Returns -1 if the block is invisible |
| 851 | // Returns 0 if not |
| 852 | int EvaluateBlockcxx . . $ EvaluateBlock(2326284602b0bb2d).(int x, int z, int lod) { |
| 853 | float delta; |
| 854 | int simplemul = 1 << ((MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1) - lod); |
| 855 | |
| 856 | #if (defined(EDITOR) || defined(NEWEDITOR)) |
| 857 | if (View_mode == EDITOR_MODE && Editor_LOD_engine_off) |
| 858 | return 0; |
| 859 | #endif |
| 860 | |
| 861 | if (View_modecxx . . $ View_mode. != EDITOR_MODEcxx . . $ EDITOR_MODE. && Terrain_LOD_engine_offcxx . . $ Terrain_LOD_engine_off.) |
| 862 | return 0; |
| 863 | |
| 864 | delta = TerrainDeltaBlockscxx . . $ TerrainDeltaBlocks.[lod][((z / simplemul) * (TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! / simplemul)) + (x / simplemul)]; |
| 865 | |
| 866 | if (delta == SHUTOFF_LOD_INVISIBLEcxx . . $ `Descent3/terrain.h:40:9`!) |
| 867 | return -1; // This block is completely invisible |
| 868 | |
| 869 | // if (SimplifyVertexSlow (x+(simplemul/2),z+(simplemul/2),delta)) |
| 870 | // return 1; |
| 871 | |
| 872 | if (SimplifyVertexcxx . . $ SimplifyVertex(1df3af30621f6c78).(x + (simplemul / 2), z + (simplemul / 2), delta)) |
| 873 | return 1; |
| 874 | |
| 875 | return 0; |
| 876 | } |
| 877 | |
| 878 | // Shuts off LOD for a given cell |
| 879 | void TurnOffLODForCellcxx . . $ TurnOffLODForCell(d4f767463ce0a6b3).(int cellnum) { |
| 880 | if (Dedicated_servercxx . . $ Dedicated_server.) |
| 881 | return; |
| 882 | |
| 883 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(cellnum >= 0 && cellnum < (TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! * TERRAIN_DEPTHcxx . . $ `Descent3/terrain.h:32:9`!)); |
| 884 | int x = cellnum % TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!; |
| 885 | int z = cellnum / TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!; |
| 886 | |
| 887 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(Num_lodoffs < MAX_LODOFFScxx . . $ `Descent3/TerrainSearch.cpp:243:9`!); |
| 888 | LODOffscxx . . $ LODOffs.[Num_lodoffscxx . . $ Num_lodoffs.].cellnumcxx . . $ lodoff#cellnum. = cellnum; |
| 889 | |
| 890 | for (int i = 0; i < MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1; i++) { |
| 891 | float delta; |
| 892 | int simplemul = 1 << ((MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1) - i); |
| 893 | |
| 894 | delta = TerrainDeltaBlockscxx . . $ TerrainDeltaBlocks.[i][((z / simplemul) * (TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! / simplemul)) + (x / simplemul)]; |
| 895 | LODOffscxx . . $ LODOffs.[Num_lodoffscxx . . $ Num_lodoffs.].save_deltacxx . . $ lodoff#save_delta.[i] = delta; |
| 896 | TerrainDeltaBlockscxx . . $ TerrainDeltaBlocks.[i][((z / simplemul) * (TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! / simplemul)) + (x / simplemul)] = SHUTOFF_LOD_DELTAcxx . . $ `Descent3/terrain.h:39:9`!; |
| 897 | } |
| 898 | |
| 899 | Num_lodoffscxx . . $ Num_lodoffs.++; |
| 900 | } |
| 901 | |
| 902 | // Restores the terrain deltas to their original state |
| 903 | void ClearLODOffscxx . . $ ClearLODOffs(49f6e7a06ebc5aa8).() { |
| 904 | for (int t = Num_lodoffscxx . . $ Num_lodoffs. - 1; t >= 0; t--) { |
| 905 | int cellnum = LODOffscxx . . $ LODOffs.[t].cellnumcxx . . $ lodoff#cellnum.; |
| 906 | |
| 907 | int x = cellnum % TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!; |
| 908 | int z = cellnum / TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`!; |
| 909 | |
| 910 | for (int i = 0; i < MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1; i++) { |
| 911 | int simplemul = 1 << ((MAX_TERRAIN_LODcxx . . $ `Descent3/terrain.h:38:9`! - 1) - i); |
| 912 | TerrainDeltaBlockscxx . . $ TerrainDeltaBlocks.[i][((z / simplemul) * (TERRAIN_WIDTHcxx . . $ `Descent3/terrain.h:31:9`! / simplemul)) + (x / simplemul)] = |
| 913 | LODOffscxx . . $ LODOffs.[t].save_deltacxx . . $ lodoff#save_delta.[i]; |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | Num_lodoffscxx . . $ Num_lodoffs. = 0; |
| 918 | } |