| 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 | * $Source: $ |
| 21 | * $Revision: 8 $ |
| 22 | * $Author: Samir $ |
| 23 | * $Date: 8/13/99 2:00p $ |
| 24 | * |
| 25 | * |
| 26 | * |
| 27 | * $Log: /DescentIII/Main/sndlib/sndrender.cpp $ |
| 28 | * |
| 29 | * 8 8/13/99 2:00p Samir |
| 30 | * more aureal and geometry fixes. |
| 31 | * |
| 32 | * 7 8/11/99 3:12p Samir |
| 33 | * fixes for aureal support. |
| 34 | * |
| 35 | * 6 5/13/99 3:49p Ardussi |
| 36 | * changes for compiling on the Mac |
| 37 | * |
| 38 | * 5 4/16/99 3:33a Jeff |
| 39 | * ifdefs added to remove windows specific code |
| 40 | * |
| 41 | * 4 4/14/99 10:46a Kevin |
| 42 | * Removed OutrageMessageBox from release builds |
| 43 | * |
| 44 | * 3 4/06/99 8:30p Samir |
| 45 | * added reflection support. |
| 46 | * |
| 47 | * 2 4/01/99 4:28p Samir |
| 48 | * hardware geometry integration if it's available. |
| 49 | * |
| 50 | */ |
| 51 | |
| 52 | #include <cstring> |
| 53 | |
| 54 | #include "hlsoundlib.h"cxx . . $ `<file>/sndlib/hlsoundlib.h`/ |
| 55 | #include "ddsndgeometry.h"cxx . . $ `<file>/sndlib/ddsndgeometry.h`/ |
| 56 | #include "sndrender.h"cxx . . $ `<file>/sndlib/sndrender.h`/ |
| 57 | #include "room.h"cxx . . $ `<file>/Descent3/room.h`/ |
| 58 | #include "object.h"cxx . . $ `<file>/Descent3/object.h`/ |
| 59 | #include "application.h"cxx . . $ `<file>/lib/application.h`/ |
| 60 | #include "soundload.h"cxx . . $ `<file>/sndlib/soundload.h`/ |
| 61 | #include "gametexture.h"cxx . . $ `<file>/Descent3/gametexture.h`/ |
| 62 | |
| 63 | |
| 64 | static llsGeometrycxx . . $ llsGeometry# *Geometrycxx . . $ Geometry. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 65 | static int16_t Sound_room_listcxx . . $ Sound_room_list.[SOUND_RENDER_ROOM_LIMITcxx . . $ `sndlib/sndrender.h:43:9`! + 1]; |
| 66 | |
| 67 | // resets sound geometry system (called beginning of each level) |
| 68 | void SoundRenderResetcxx . . $ SoundRenderReset(49f6e7a06ebc5aa8).() { Sound_room_listcxx . . $ Sound_room_list.[0] = -1; } |
| 69 | |
| 70 | // if this fails, renderer won't work, do emulation. |
| 71 | bool sound_render_start_framecxx . . $ sound_render_start_frame(c9857a73d68e59ba).() { |
| 72 | Geometrycxx . . $ Geometry. = Sound_systemcxx . . $ Sound_system..m_ll_sound_ptrcxx . . $ hlsSystem#m_ll_sound_ptr.->GetGeometryInterfacecxx . . $ llsSystem#GetGeometryInterface(d4b170b416b3ba56).(); |
| 73 | if (Geometrycxx . . $ Geometry.) { |
| 74 | Geometrycxx . . $ Geometry.->StartFramecxx . . $ llsGeometry#StartFrame(49f6e7a06ebc5aa8).(); |
| 75 | } |
| 76 | return Geometrycxx . . $ Geometry. ? true : false; |
| 77 | } |
| 78 | |
| 79 | // ends a frame |
| 80 | void sound_render_end_framecxx . . $ sound_render_end_frame(49f6e7a06ebc5aa8).() { |
| 81 | if (Geometrycxx . . $ Geometry.) { |
| 82 | Geometrycxx . . $ Geometry.->EndFramecxx . . $ llsGeometry#EndFrame(49f6e7a06ebc5aa8).(); |
| 83 | } |
| 84 | Geometrycxx . . $ Geometry. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 85 | } |
| 86 | |
| 87 | // render one room's geometry |
| 88 | // dont render portal faces! |
| 89 | void sound_render_room_geometrycxx . . $ sound_render_room_geometry(3e454b8ccf442868).(int iroom, int slot) { |
| 90 | int iface, reflect_face; |
| 91 | roomcxx . . $ room# *rp; |
| 92 | facecxx . . $ face# *rfacelist; |
| 93 | vectorcxx . . $ vector# *vertlist[MAX_VERTS_PER_FACEcxx . . $ `Descent3/room_external.h:108:9`!]; |
| 94 | unsigned room_tag = (iroom << 20); // 12 bits for room (4096 rooms max per level) |
| 95 | // 14 bits for faces (16384 faces per room) |
| 96 | // 6 bits per face (64 primatives per face.) |
| 97 | unsigned face_tag; |
| 98 | |
| 99 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(Geometry); |
| 100 | if (iroom == -1) { |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | if (iroom != Sound_room_listcxx . . $ Sound_room_list.[slot]) { |
| 105 | if (ROOMNUM_OUTSIDEcxx . . $ `lib/object_external_struct.h:127:9`!(iroom)) { |
| 106 | Geometrycxx . . $ Geometry.->Clearcxx . . $ llsGeometry#Clear(49f6e7a06ebc5aa8).(); |
| 107 | Sound_room_listcxx . . $ Sound_room_list.[slot] = iroom; |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | Geometrycxx . . $ Geometry.->StartPolygonGroupcxx . . $ llsGeometry#StartPolygonGroup(d4f767463ce0a6b3).(slot); |
| 112 | |
| 113 | rp = &Roomscxx . . $ Rooms.[iroom]; |
| 114 | rfacelist = rp->facescxx . . $ room#faces.; |
| 115 | |
| 116 | // for now, lets create the geometry for the current room the viewer is in. |
| 117 | for (iface = 0, reflect_face = 0; iface < rp->num_facescxx . . $ room#num_faces.; iface++, reflect_face = (iface / 3)) { |
| 118 | // add polygon to geometry manager |
| 119 | tSoundMaterialcxx . . $ tSoundMaterial# material = SNDGEO_MATERIAL_NONEcxx . . $ SNDGEO_MATERIAL_NONE.; |
| 120 | facecxx . . $ face# *rfacep = &rfacelist[iface]; |
| 121 | int ivert; |
| 122 | |
| 123 | face_tag = (iface << 6); |
| 124 | |
| 125 | // don't render portals! |
| 126 | if (rfacep->portal_numcxx . . $ face#portal_num. > -1) { |
| 127 | |
| 128 | } else { |
| 129 | for (ivert = 0; ivert < rfacep->num_vertscxx . . $ face#num_verts.; ivert++) { |
| 130 | vertlist[ivert] = &rp->vertscxx . . $ room#verts.[rfacep->face_vertscxx . . $ face#face_verts.[ivert]]; |
| 131 | } |
| 132 | |
| 133 | // do reflections |
| 134 | if (iface == (reflect_face * 3)) { |
| 135 | // mprintf(0, "reflect "); |
| 136 | int flags = GameTexturescxx . . $ GameTextures.[rfacep->tmapcxx . . $ face#tmap.].flagscxx . . $ texture#flags.; |
| 137 | |
| 138 | if (flags & TF_WATERcxx . . $ `Descent3/gametexture.h:202:9`!) { |
| 139 | material = SNDGEO_MATERIAL_WATERcxx . . $ SNDGEO_MATERIAL_WATER.; |
| 140 | } else if (flags & TF_METALcxx . . $ `Descent3/gametexture.h:203:9`!) { |
| 141 | material = SNDGEO_MATERIAL_METALcxx . . $ SNDGEO_MATERIAL_METAL.; |
| 142 | } else { |
| 143 | material = SNDGEO_MATERIAL_ROCKcxx . . $ SNDGEO_MATERIAL_ROCK.; |
| 144 | } |
| 145 | } |
| 146 | Geometrycxx . . $ Geometry.->AddPolycxx . . $ llsGeometry#AddPoly(f4a69767f128d).(rfacep->num_vertscxx . . $ face#num_verts., vertlist, (room_tag + face_tag), material); |
| 147 | } |
| 148 | } |
| 149 | Geometrycxx . . $ Geometry.->EndPolygonGroupcxx . . $ llsGeometry#EndPolygonGroup(d4f767463ce0a6b3).(slot); |
| 150 | Geometrycxx . . $ Geometry.->RenderGroupcxx . . $ llsGeometry#RenderGroup(d4f767463ce0a6b3).(slot); |
| 151 | Sound_room_listcxx . . $ Sound_room_list.[slot] = iroom; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | // render all rooms within a certain radius from player |
| 156 | // the radius is actually scaled according to orientation. radius is maximum radius, really, which is forward |
| 157 | // |
| 158 | // returns rooms rendered, terminate list with -1. |
| 159 | // |
| 160 | // algorithm: |
| 161 | // |
| 162 | // routine (Ci,Ri) |
| 163 | // start at listener position in room Ri (i=0) |
| 164 | // render room Ri |
| 165 | // for each portal, connect to room Rj. |
| 166 | // take care of special cases like doors, which are 'openings' |
| 167 | // find center point in Cj. |
| 168 | // if Distance(Cj,Ci)) < (max_radius*Orient(R0)) then |
| 169 | // call routine(Cj,Rj) |
| 170 | // else |
| 171 | // end routine |
| 172 | // endif |
| 173 | // next portal |
| 174 | // end routine |
| 175 | // |
| 176 | int16_t *sound_render_audible_roomscxx . . $ sound_render_audible_rooms(62024859d2e566e1).(pos_statecxx . . $ pos_state# *listener_pos, float max_radius) { |
| 177 | int iroom = 0; |
| 178 | |
| 179 | sound_render_room_geometrycxx . . $ sound_render_room_geometry(3e454b8ccf442868).(listener_pos->roomnumcxx . . $ pos_state#roomnum., iroom); |
| 180 | Sound_room_listcxx . . $ Sound_room_list.[iroom + 1] = -1; |
| 181 | |
| 182 | return (int16_t *)Sound_room_listcxx . . $ Sound_room_list.; |
| 183 | } |