Debian Codegraph @

Descent3/room.h

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 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/main/room.h $
21 * $Revision: 104 $
22 * $Date: 5/05/99 5:03a $
23 * $Author: Gwar $
24 *
25 * Room structures & functions
26 *
27 * $Log: /DescentIII/main/room.h $
28 *
29 * 104 5/05/99 5:03a Gwar
30 * renamed ned_GameTextures array to GameTextures in new editor to make
31 * game code happy; 3D texture view still does not display textures
32 *
33 * 103 4/30/99 12:56p Kevin
34 * Lowered values for MAX_SOUNDS, MAX_ROOMS, MAX_TEXTURES and MAX_OBJIDS.
35 * Talk to me before changing any of these again.
36 *
37 * 102 4/21/99 5:33a Gwar
38 * added a NEWEDITOR #define
39 *
40 * 101 3/24/99 3:27p Matt
41 * Increased the max number of room changes from 20 to 100.
42 *
43 * 100 2/09/99 9:59a Chris
44 * Massive BOA update :) Terrain happy now. Vis happy now. Sound happy
45 * now.
46 *
47 * 99 1/21/99 11:15p Jeff
48 * pulled out some structs and defines from header files and moved them
49 * into seperate header files so that multiplayer dlls don't require major
50 * game headers, just those new headers. Side effect is a shorter build
51 * time. Also cleaned up some header file #includes that weren't needed.
52 * This affected polymodel.h, object.h, player.h, vecmat.h, room.h,
53 * manage.h and multi.h
54 *
55 * 98 1/21/99 11:34a Matt
56 * Got rid of portal triggers. Since we don't have multi-face portals, a
57 * face trigger works fine for a portal. Also fixed a few editor/trigger
58 * bugs.
59 *
60 * 97 1/21/99 11:20a Jason
61 * added a two new flags: strobe and flicker
62 *
63 * 96 1/20/99 6:11p Matt
64 * Fixed a couple bugs in the room wind/fog change system, and make the
65 * values change from current -> new instead of start -> end.
66 *
67 * 95 1/19/99 11:25a Jason
68 * added room (fog and wind) changing functions
69 *
70 * 94 1/15/99 3:14p Jason
71 * added combinable portals
72 *
73 * 93 1/11/99 11:17a Jason
74 * made fog not have that stupid telltale z problem
75 *
76 * 92 1/08/99 5:37p Samir
77 * reverb values per room.
78 *
79 * 91 12/22/98 2:03p Matt
80 * Added room names, and made rooms not compress so that room numbers are
81 * suitable for persistant uses.
82 *
83 * 90 11/30/98 3:59p Jason
84 * changed dynamic lighting to be better
85 *
86 * 89 11/02/98 6:15p Chris
87 * Room AABBs get saved with the level and the sort_face and dec_sort_face
88 * list s have been removed
89 *
90 * 88 10/06/98 6:08p Jason
91 * added RF_TRIANGULATE so that special rooms (with non-planar UVS) can be
92 * drawn correctly
93 *
94 * 87 10/01/98 10:33a Jason
95 * added room_change_flags
96 *
97 * 86 9/22/98 6:58p Samir
98 * Render_floating_triggers is _DEBUG code, so make it so.
99 *
100 * 85 9/22/98 3:55p Samir
101 * ifdef out stuff for non-debug version.
102 *
103 * 84 9/08/98 12:05p Jason
104 * moved doorway.h out of room.h
105 *
106 * 83 9/01/98 12:04p Matt
107 * Ripped out multi-face portal code
108 *
109 * 82 8/28/98 4:44p Jason
110 * optimized mirror rendering
111 *
112 * 81 8/27/98 5:19p Jason
113 * added first rev of reflected surfaces
114 *
115 * 80 8/19/98 2:17p Jeff
116 * made a function to change the texture on a face
117 *
118 * 79 8/17/98 6:40p Matt
119 * Added ambient sound system
120 *
121 * 78 7/21/98 2:14p Chris
122 * Some FVI speedups - not done
123 *
124 * 77 7/17/98 9:56a Chris
125 * Intermediate checkin
126 *
127 * 76 7/16/98 8:29p Chris
128 * Partial implementation of the new collide code
129 *
130 * 75 7/16/98 12:06p Jason
131 * added special flags to room structure
132 *
133 * 74 6/08/98 12:28p Matt
134 * Removed unused face flag, and changed some commenting.
135 *
136 * 73 6/05/98 5:22p Jason
137 * added volumetric fog
138 *
139 * 72 6/02/98 6:03p Jason
140 * added specular lightmaps
141 *
142 * 71 5/26/98 5:56p Jason
143 * only render coronas which are flagged
144 *
145 * 70 5/25/98 3:46p Jason
146 * added better light glows
147 *
148 * 69 5/22/98 3:26p Jason
149 * added better memory management for specular lighting
150 *
151 * 68 5/22/98 12:34p Matt
152 * Added scorch mark/bullet hole system.
153 *
154 * 67 5/15/98 5:41p Jason
155 * implemented volume lighting system
156 *
157 * 66 5/06/98 12:55p Jason
158 * did some vis effect optimizations
159 *
160 * 65 4/30/98 5:50p Jason
161 * more framerate optimizations
162 *
163 * 64 4/30/98 12:37p Jason
164 * added FF_FACING for non-backfaces
165 *
166 * 63 4/22/98 12:38p Chris
167 * Added path points to portals and rooms. Improved BOA auto-making
168 * process.
169 *
170 * 62 4/02/98 12:24p Jason
171 * trimmed some fat from our structures
172 *
173 * 61 3/18/98 4:31p Chris
174 * Speed up fvi and fixed some bugs
175 *
176 * 60 3/16/98 6:41p Jason
177 * added goal room stuff
178 *
179 * 59 3/16/98 5:50p Chris
180 * Added sorted face lists for fvi
181 *
182 * 58 3/13/98 12:05p Matt
183 * Changed the way we determine whether to render past a closed door to
184 * fix a render bug when the viewer is in a door room.
185 * Moved FaceIsRenderabl(), GetFaceAlpha(), and RenderPastPortal() from
186 * room.h to render.cpp.
187 *
188 * 57 3/06/98 3:23p Jason
189 * added lighting from satellites to indoor rooms
190 *
191 * 56 2/23/98 6:50p Jason
192 * changes to help facilitate fast lighting with shadow volumes
193 *
194 *
195 * 55 2/18/98 1:21p Jason
196 * upped max lightmap count
197 *
198 * 54 2/11/98 7:01p Chris
199 * Started to add wind
200 *
201 * 53 2/11/98 11:48a Matt
202 * Fixed alignment in room struct.
203 *
204 * 52 2/10/98 7:45p Matt
205 * Added (probably temporary) flags for goals
206 *
207 * 51 2/10/98 3:49p Jason
208 * added pulsing walls
209 *
210 * 50 2/10/98 1:12p Jason
211 * added forcefields and saturating walls
212 *
213 * 49 2/04/98 8:25p Jason
214 * added light multiplier for faces
215 *
216 * 48 2/02/98 7:07p Matt
217 * Added support for doors that can be seen through even when closed
218 *
219 * 47 2/02/98 5:13p Matt
220 * Added more generic function to compute a surface normal for a face
221 *
222 * 46 1/20/98 12:10p Jason
223 * implemented vis effect system
224 *
225 * 45 1/15/98 7:34p Matt
226 * Revamped error checking when computing face normals
227 *
228 * 44 1/15/98 3:47p Jason
229 * sped up room rendering on the terrain
230 *
231 * 43 1/12/98 3:34p Jason
232 * sped up indoor rendering by clipping faces against portals
233 *
234 * 42 11/24/97 1:30a Jason
235 * first attempt at adding shadows
236 *
237 * 41 11/14/97 9:02p Mark
238 * Increased the number of rooms from 100 to 500 (Matt on Mark's machine)
239 *
240 * 40 11/14/97 6:39p Jason
241 * added ability to do lighting on a single room
242 *
243 * 39 10/13/97 5:08p Matt
244 * Moved ComputeRoomBoundingSphere() & CreateRoomObjects() from editor to
245 * main
246 *
247 *
248 * 38 10/10/97 11:38a Jason
249 * put in better volumetric support
250 *
251 * 37 10/08/97 2:28p Jason
252 * got external rooms working with terrain lighting
253 *
254 * 36 10/01/97 7:51p Matt
255 * Added code for external rooms
256 *
257 * 35 9/19/97 8:09p Jason
258 * optimizations for dynamic lighting
259 *
260 * 34 9/19/97 2:52p Jason
261 * changes to fix lightmap seam problem
262 *
263 * 33 9/17/97 6:14p Jason
264 * did some optimizations due to running vtune
265 *
266 * 32 9/16/97 4:27p Matt
267 * Got rid of static_light & changed fields in the room struct
268 *
269 * 31 9/16/97 1:07a Matt
270 * Fixed rendering past open doors
271 *
272 * 30 9/15/97 5:33p Jason
273 * made portals check for doors
274 *
275 * 29 9/12/97 5:38p Jason
276 * got doors working
277 *
278 * 28 9/12/97 2:35p Matt
279 * Changed face flags to a word, and added destroyed flag
280 *
281 * 27 9/11/97 3:13p Matt
282 * Several more-or-less small changes, mostly with portal triggers
283 *
284 * 26 9/10/97 5:13p Matt
285 * Changed some flags & added a few functions
286 *
287 * 25 9/09/97 12:21p Matt
288 * Added new flags, deleted old ones, renamed others
289 * Added new functions
290 * Cleaned up structs, fixing alignment
291 *
292 * 24 9/06/97 10:53p Matt
293 * Added portal and face flags
294 *
295 * 23 9/04/97 11:23a Jason
296 * sped up dynamic light computation a bit
297 *
298 * 22 9/02/97 5:17p Jason
299 * changes for dynamic lighting
300 *
301 * 21 9/02/97 12:55p Jason
302 * classify faces as alphaed or not
303 *
304 * 20 8/28/97 12:31p Jason
305 * added hi-res lightmaps for radiosity
306 *
307 * 19 8/19/97 1:13p Jason
308 * added GetAreaForFace function
309 *
310 * 18 8/13/97 11:53a Jason
311 * moved ClearAllRoomLightmaps into room.cpp where it belongs
312 *
313 * 17 8/12/97 3:51p Jason
314 * tweaked lightmaps with radiosity
315 *
316 * 16 8/12/97 1:13p Chris
317 * Added AABBs.
318 *
319 * 15 8/12/97 1:10a Jason
320 * added code to support radiosity lighting
321 *
322 * 14 8/11/97 3:55p Chris
323 * Added a function to compute the rough center of a portal
324 *
325 * 13 8/04/97 5:35p Chris
326 *
327 * 12 8/01/97 4:38p Chris
328 *
329 * 11 7/18/97 5:36p Jason
330 * save changed paletted rooms on exit
331 *
332 * 10 7/17/97 11:50a Jason
333 * Upped max_Verts_per_face to 64
334 *
335 * 9 7/16/97 1:50p Sean
336 * from JASON: upped max face limit to 3000
337 *
338 * 8 6/30/97 1:30p Jason
339 * added netherspace stuff
340 *
341 * 7 6/27/97 4:15p Jason
342 * added more room functions
343 *
344 * 6 6/27/97 3:04p Jason
345 * added cool room stuff
346 *
347 * 5 6/26/97 2:37p Jason
348 * added combine_faces function and texturing to rooms
349 *
350 * 4 6/25/97 5:29p Jason
351 * added/modified code to display a room
352 *
353 * 3 6/24/97 1:51p Jason
354 *
355 * 2 6/18/97 12:40p Jason
356 * added include files
357 *
358 * 1 6/18/97 12:39p Jason
359 *
360 * $NoKeywords: $
361 */
362
363 #ifndef _ROOM_H
364 #define _ROOM_H
365
366 #include "pstypes.h"
367 #include "vecmat_external.h"
368 #include "gametexture.h"
369
370 #ifdef NEWEDITOR
371 #include "..\neweditor\ned_GameTexture.h"
372 #endif
373
374 #include "room_external.h"
375
376 // Sizes for some global arrays
377 #define MAX_ROOMS 400 // max number of rooms in the world
378
379 // Constants for room palette (editor-specific)
380 #if (defined(EDITOR) || defined(NEWEDITOR))
381 #define FIRST_PALETTE_ROOM MAX_ROOMS // start of rooms for palette
382 #define MAX_PALETTE_ROOMS 50 // max number of loaded rooms
383 #else
384 #define MAX_PALETTE_ROOMS 0 // max number of loaded rooms
385 #endif
386
387 // Room change stuff
388 #define MAX_ROOM_CHANGES 100
389 struct room_changes {
390 int roomnum;
391 bool fog;
392 vector start_vector, end_vector;
393 float start_depth, end_depth;
394 float start_time;
395 float total_time;
396 uint8_t used;
397 };
398
399 //
400 // Globals
401 //
402
403 extern room Rooms[]; // global sparse array of rooms
404 extern int Highest_room_index; // index of highest-numbered room
405
406 //
407 // Macros
408 //
409
410 // Handy macro to convert a room ptr to a room number
411 #define ROOMNUM(r) (r - Rooms)
412
413 // See above from RF_MINE_MASK
414 #define MINE_INDEX(x) ((Rooms[x].flags & RFM_MINE) >> 20)
415
416 //
417 // Functions
418 //
419
420 // Zeroes out the rooms array
421 void InitRooms();
422
423 #if (defined(_DEBUG) || defined(EDITOR))
424 // Allows a spew'er to find out if he is in a room or external to the mine
425 // NOTE: THIS FUNCTION IS NOT FOR IN GAME STUFF. It is REALLY SLOW and accurate.
426 // Talk to Chris if you need something like this function.
427 int FindPointRoom(vector *pnt);
428
429 // Put this here so we don't need to include render.h
430 extern bool Render_floating_triggers;
431
432 #endif
433
434 // Initalize a room, allocating memory and filling in fields
435 // Parameters: rp - the room to be initialized
436 // nverts - how many vertices this room will have
437 // nfaces - how many faces this room wil have
438 // nfaces - how many portals this room wil have
439 void InitRoom(room *rp, int nverts, int nfaces, int nportals);
440
441 // Initialize a room face structure, allocating memory for vertlist and uvls
442 void InitRoomFace(face *fp, int nverts);
443
444 // Frees a room, deallocating its memory and marking it as unused
445 void FreeRoom(room *rp);
446
447 // Frees all the rooms currently in use, deallocating their memory and marking them as unused
448 void FreeAllRooms();
449
450 // Finds the center point of a room
451 // Parameters: vp - filled in with the center point
452 // rp - the room whose center to find
453 void ComputeRoomCenter(vector *vp, room *rp);
454
455 // Computes (fills in) the surface normal of a face.
456 // Finds the best normal on this face by checking all sets of three vertices
457 // IMPORTANT: The caller should really check the return value of this function
458 // Parameters: rp,facenum - the room and face to calculate the normal for
459 // Returns: true if the normal is ok
460 // false if the normal has a very small (pre-normalization) magnitude
461 bool ComputeFaceNormal(room *rp, int facenum);
462
463 // Compute the surface normal from a list of vertices that determine a face
464 // Finds the best normal on this face by checking all sets of three vertices
465 // IMPORTANT: The caller should really check the return value of this function
466 // Parameters: normal - this is filled in with the normal
467 // num_verts - how many vertices in the face
468 // vertnum_list - a list of vertex numbers for this face. these index into verts
469 // verts - the array of vertices into which the elements of vertnum_list index
470 // Returns: true if the normal is ok
471 // false if the normal has a very small (pre-normalization) magnitude
472 bool ComputeNormal(vector *normal, int num_verts, short *vertnum_list, vector *verts);
473
474 // Finds the center point of a portal by averaging the points in the portal
475 // Parameters: vp - filled in with the center point
476 // rp - the room
477 // portal_index - the index of the portal whose center to find
478 void ComputePortalCenter(vector *vp, room *rp, int portal_index);
479
480 // Computes the center point on a face by averaging the points in the face
481 void ComputeCenterPointOnFace(vector *vp, room *rp, int facenum);
482
483 // Free the memory used by a room face structure
484 void FreeRoomFace(face *fp);
485
486 // Removes all room lightmaps from memory and sets indoor faces accordingly
487 void ClearAllRoomLightmaps(int external);
488
489 // Removes all room volume lights from memory
490 void ClearAllVolumeLights();
491
492 // Returns the area taken up by a face
493 float GetAreaForFace(room *rp, int facenum);
494
495 // Check if a particular point on a wall is a transparent pixel
496 // Parameters: pnt - the point we're checking
497 // rp - pointer to the room that pnt is in
498 // facenum - the face that pnt is on
499 // Returns: true if can pass through the given point, else 0
500 int CheckTransparentPoint(const vector *pnt, const room *rp, const int facenum);
501
502 // Face physics flags returned by GetFacePhysicsFlags()
503 // Note that:
504 // it is illegal for a face to have both SOLID and TRANSPARENT
505 // it is legal, but probably not of interest, for a face to have SOLID & PORTAL
506 #define FPF_SOLID 1 // nothing passes through this face
507 #define FPF_TRANSPARENT 2 // face has transparency, so some things may be able to fly through it
508 #define FPF_PORTAL 4 // this face is in a portal.
509 #define FPF_RECORD 8 // take note of when an object passes through this face
510
511 // Face physics types. These are combinations of the above flags
512 #define FPT_IGNORE 0 // completey ignore this face
513
514 // Figure out how the physics should deal with a given face
515 // Parameters: rp - pointer to the room the face is in
516 // fp - the face we're interested in
517 // Returns: bitmask of flags (see above).
518 static inline int GetFacePhysicsFlags(const room *rp, const face *fp) {
519 int ret = 0;
520
521 // If face is a trigger, must record
522 if (fp->flags & FF_HAS_TRIGGER)
523 ret |= FPF_RECORD;
524
525 // If it's a floating trigger, then we're done
526 if (fp->flags & FF_FLOATING_TRIG)
527 return ret;
528
529 if (fp->flags & FF_VOLUMETRIC)
530 return ret;
531
532 // Deal with faces that are part of a portal
533 if (fp->portal_num != -1) {
534 portal *pp = &rp->portals[fp->portal_num];
535
536 // Mark as portal
537 ret |= FPF_PORTAL;
538
539 // Face is flythrough if we don't render the portal faces, or it's marked rendered flythrough
540 if (!(pp->flags & PF_RENDER_FACES) || (pp->flags & PF_RENDERED_FLYTHROUGH))
541 return ret;
542 }
543
544 // If we're here, it's either a non-portal face, or portal face that gets rendered
545
546 // Check if the face is marked fly-through
547 if (GameTextures[fp->tmap].flags & TF_FLY_THRU)
548 return ret;
549
550 // Check if the face is solid or transparent
551 int bm_handle = GetTextureBitmap(fp->tmap, 0);
552 if (GameBitmaps[bm_handle].flags & BF_TRANSPARENT)
553 ret |= FPF_TRANSPARENT;
554 else
555 ret |= FPF_SOLID;
556
557 // We're done
558 return ret;
559 }
560
561 // Computes a bounding sphere for the current room
562 // Parameters: center - filled in with the center point of the sphere
563 // rp - the room we're bounding
564 // Returns: the radius of the bounding sphere
565 float ComputeRoomBoundingSphere(vector *center, room *rp);
566
567 // Create objects for the external rooms
568 void CreateRoomObjects();
569
570 // Clears lightmaps for a single room
571 void ClearRoomLightmaps(int roomnum);
572
573 // returns the index of the first room that is being used. Returns -1 if there are none
574 int FindFirstUsedRoom();
575
576 // Clears specmaps for a single room
577 void ClearRoomSpecmaps(int roomnum);
578
579 // Removes all room specularity maps from memory and sets indoor faces accordingly
580 // External=1 means to perform the operation on external rooms only, 0 means indoor rooms only
581 void ClearAllRoomSpecmaps(int external);
582
583 extern void GetIJ(const vector *normal, int *ii, int *jj);
584
585 // Changes a face's texture within a room
586 // returns true on successs
587 bool ChangeRoomFaceTexture(int room_num, int face_num, int texture);
588
589 // Clears the data for room changes
590 void ClearRoomChanges();
591
592 // Returns index of room change allocatd, else -1 on error
593 int AllocRoomChange();
594
595 // Does whatever fading/changing of room stuff that needs to be done this frame
596 void DoRoomChangeFrame();
597
598 // Sets up a room to change its fog or wind over time
599 int SetRoomChangeOverTime(int roomnum, bool fog, vector *end, float depth_end, float time);
600
601 #endif