| 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/postrender.cpp $ |
| 21 | * $Revision: 15 $ |
| 22 | * $Date: 4/19/00 5:16p $ |
| 23 | * $Author: Matt $ |
| 24 | * |
| 25 | * program state info |
| 26 | * |
| 27 | * $Log: /DescentIII/main/postrender.cpp $ |
| 28 | * |
| 29 | * 15 4/19/00 5:16p Matt |
| 30 | * From Duane for 1.4 |
| 31 | * Removed Mac OpenGL hack |
| 32 | * |
| 33 | * 14 10/21/99 9:28p Jeff |
| 34 | * B.A. Macintosh code merge |
| 35 | * |
| 36 | * 13 6/08/99 12:12p Jeff |
| 37 | * fixed warning messages when compiling new editor |
| 38 | * |
| 39 | * 12 5/12/99 4:55p Gwar |
| 40 | * added an include for the NEWEDITOR |
| 41 | * |
| 42 | * 11 3/22/99 5:51p Jason |
| 43 | * enhancements to mirrors |
| 44 | * |
| 45 | * 10 2/17/99 1:59p Jason |
| 46 | * fixed some postrender issues |
| 47 | * |
| 48 | * 9 2/16/99 5:25p Matt |
| 49 | * zero out Num_postrenders after rendering |
| 50 | * |
| 51 | * 8 2/10/99 1:34p Dan |
| 52 | * fixed another assert |
| 53 | * |
| 54 | * 7 2/10/99 11:41a Dan |
| 55 | * fixed assertion |
| 56 | * |
| 57 | * 6 2/09/99 1:12p Jason |
| 58 | * fixed sorting problem with postrender |
| 59 | * |
| 60 | * 5 2/09/99 12:59p Jason |
| 61 | * spedup indoor renderer |
| 62 | * |
| 63 | * 4 2/09/99 12:09p Jason |
| 64 | * rewriting indoor engine... |
| 65 | * |
| 66 | * 3 2/09/99 9:59a Chris |
| 67 | * Quick compile patch |
| 68 | * |
| 69 | * 2 2/08/99 6:39p Jason |
| 70 | * first pass at new indoor engine |
| 71 | * |
| 72 | * $NoKeywords: $ |
| 73 | */ |
| 74 | |
| 75 | #ifdef NEWEDITOR // include first to get rid of ugly warning message about macro redfinitions |
| 76 | #include "..\neweditor\globals.h" |
| 77 | #endif |
| 78 | |
| 79 | #include <stdlib.h> |
| 80 | #include "object.h"cxx . . $ `<file>/Descent3/object.h`/ |
| 81 | #include "viseffect.h"cxx . . $ `<file>/Descent3/viseffect.h`/ |
| 82 | #include "render.h"cxx . . $ `<file>/Descent3/render.h`/ |
| 83 | #include "renderobject.h"cxx . . $ `<file>/Descent3/renderobject.h`/ |
| 84 | #include "room.h"cxx . . $ `<file>/Descent3/room.h`/ |
| 85 | #include "postrender.h"cxx . . $ `<file>/Descent3/postrender.h`/ |
| 86 | #include "config.h"cxx . . $ `<file>/Descent3/config.h`/ |
| 87 | #include "terrain.h"cxx . . $ `<file>/Descent3/terrain.h`/ |
| 88 | #include "renderer.h"cxx . . $ `<file>/lib/renderer.h`/ |
| 89 | |
| 90 | postrender_structcxx . . $ postrender_struct# Postrender_listcxx . . $ Postrender_list.[MAX_POSTRENDERScxx . . $ `Descent3/postrender.h:22:9`!]; |
| 91 | int Num_postrenderscxx . . $ Num_postrenders. = 0; |
| 92 | |
| 93 | static vectorcxx . . $ vector# Viewer_eyecxx . . $ Viewer_eye.; |
| 94 | static matrixcxx . . $ matrix# Viewer_orientcxx . . $ Viewer_orient.; |
| 95 | static int Viewer_roomnumcxx . . $ Viewer_roomnum.; |
| 96 | |
| 97 | // Resets out postrender list for a new frame |
| 98 | void ResetPostrenderListcxx . . $ ResetPostrenderList(49f6e7a06ebc5aa8).() { Num_postrenderscxx . . $ Num_postrenders. = 0; } |
| 99 | |
| 100 | // Compare function for room face sort |
| 101 | static int Postrender_sort_funccxx . . $ Postrender_sort_func(95ee37a24ca5bb99).(const postrender_structcxx . . $ postrender_struct# *a, const postrender_structcxx . . $ postrender_struct# *b) { |
| 102 | if (a->zcxx . . $ postrender_struct#z. < b->zcxx . . $ postrender_struct#z.) |
| 103 | return -1; |
| 104 | else if (a->zcxx . . $ postrender_struct#z. > b->zcxx . . $ postrender_struct#z.) |
| 105 | return 1; |
| 106 | else |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | #define STATE_PUSHcxx . . $ `Descent3/postrender.cpp:110:9`!(val) \ |
| 111 | { \ |
| 112 | state_stack[state_stack_counter] = val; \ |
| 113 | state_stack_counter++; \ |
| 114 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(state_stack_counter < 2000); \ |
| 115 | } |
| 116 | #define STATE_POPcxx . . $ `Descent3/postrender.cpp:116:9`!() \ |
| 117 | { \ |
| 118 | state_stack_counter--; \ |
| 119 | pop_val = state_stack[state_stack_counter]; \ |
| 120 | } |
| 121 | // Sorts our texture states using the quicksort algorithm |
| 122 | void SortPostrenderscxx . . $ SortPostrenders(49f6e7a06ebc5aa8).() { |
| 123 | postrender_structcxx . . $ postrender_struct# v, t; |
| 124 | int pop_val; |
| 125 | int i, j; |
| 126 | int l, r; |
| 127 | l = 0; |
| 128 | r = Num_postrenderscxx . . $ Num_postrenders. - 1; |
| 129 | |
| 130 | uint16_tcxx . . $ uint16_t# state_stack_counter = 0; |
| 131 | uint16_tcxx . . $ uint16_t# state_stack[MAX_POSTRENDERScxx . . $ `Descent3/postrender.h:22:9`!]; |
| 132 | |
| 133 | while (1) { |
| 134 | while (r > l) { |
| 135 | i = l - 1; |
| 136 | j = r; |
| 137 | v =cxx . . $ postrender_struct#`operator=`(ea242b30e5897cd3). Postrender_listcxx . . $ Postrender_list.[r]; |
| 138 | while (1) { |
| 139 | while (Postrender_listcxx . . $ Postrender_list.[++i].zcxx . . $ postrender_struct#z. < v.zcxx . . $ postrender_struct#z.) |
| 140 | ; |
| 141 | |
| 142 | while (Postrender_listcxx . . $ Postrender_list.[--j].zcxx . . $ postrender_struct#z. > v.zcxx . . $ postrender_struct#z.) |
| 143 | ; |
| 144 | |
| 145 | if (i >= j) |
| 146 | break; |
| 147 | |
| 148 | t =cxx . . $ postrender_struct#`operator=`(ea242b30e5897cd3). Postrender_listcxx . . $ Postrender_list.[i]; |
| 149 | Postrender_listcxx . . $ Postrender_list.[i] =cxx . . $ postrender_struct#`operator=`(ea242b30e5897cd3). Postrender_listcxx . . $ Postrender_list.[j]; |
| 150 | Postrender_listcxx . . $ Postrender_list.[j] =cxx . . $ postrender_struct#`operator=`(ea242b30e5897cd3). t; |
| 151 | } |
| 152 | |
| 153 | t =cxx . . $ postrender_struct#`operator=`(ea242b30e5897cd3). Postrender_listcxx . . $ Postrender_list.[i]; |
| 154 | Postrender_listcxx . . $ Postrender_list.[i] =cxx . . $ postrender_struct#`operator=`(ea242b30e5897cd3). Postrender_listcxx . . $ Postrender_list.[r]; |
| 155 | Postrender_listcxx . . $ Postrender_list.[r] =cxx . . $ postrender_struct#`operator=`(ea242b30e5897cd3). t; |
| 156 | |
| 157 | if (i - l > r - i) { |
| 158 | STATE_PUSHcxx . . $ `Descent3/postrender.cpp:110:9`!(l); |
| 159 | STATE_PUSHcxx . . $ `Descent3/postrender.cpp:110:9`!(i - 1); |
| 160 | l = i + 1; |
| 161 | } else { |
| 162 | STATE_PUSHcxx . . $ `Descent3/postrender.cpp:110:9`!(i + 1); |
| 163 | STATE_PUSHcxx . . $ `Descent3/postrender.cpp:110:9`!(r); |
| 164 | r = i - 1; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | if (!state_stack_counter) |
| 169 | break; |
| 170 | STATE_POPcxx . . $ `Descent3/postrender.cpp:116:9`!(); |
| 171 | r = pop_val; |
| 172 | STATE_POPcxx . . $ `Descent3/postrender.cpp:116:9`!(); |
| 173 | l = pop_val; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | void SetupPostrenderRoomcxx . . $ SetupPostrenderRoom(cd8c4e8cd0ee4c38).(roomcxx . . $ room# *rp) { |
| 178 | // Setup faces if this is a fogged room |
| 179 | if (rp->flagscxx . . $ room#flags. & RF_FOGcxx . . $ `Descent3/room_external.h:184:9`!) |
| 180 | SetupRoomFogcxx . . $ SetupRoomFog(2babcc7ca594dc16).(rp, &Viewer_eyecxx . . $ Viewer_eye., &Viewer_orientcxx . . $ Viewer_orient., Viewer_roomnumcxx . . $ Viewer_roomnum.); |
| 181 | } |
| 182 | |
| 183 | // Rotates a face, and then renders it |
| 184 | void DrawPostrenderFacecxx . . $ DrawPostrenderFace(6908015b96d379c0).(int roomnum, int facenum, bool change_z) { |
| 185 | int i; |
| 186 | |
| 187 | // Always draw as non state limited |
| 188 | bool save_state = StateLimitedcxx . . $ StateLimited.; |
| 189 | StateLimitedcxx . . $ StateLimited. = false; |
| 190 | |
| 191 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(roomnum >= 0 && roomnum < (MAX_ROOMScxx . . $ `Descent3/room.h:377:9`! + MAX_PALETTE_ROOMScxx . . $ `Descent3/room.h:384:9`!)); |
| 192 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(Rooms[roomnum].used); |
| 193 | |
| 194 | roomcxx . . $ room# *rp = &Roomscxx . . $ Rooms.[roomnum]; |
| 195 | |
| 196 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(facenum >= 0 && facenum < rp->num_faces); |
| 197 | |
| 198 | facecxx . . $ face# *fp = &rp->facescxx . . $ room#faces.[facenum]; |
| 199 | |
| 200 | // Rotate points |
| 201 | rp->wpb_indexcxx . . $ room#wpb_index. = 0; |
| 202 | for (i = 0; i < fp->num_vertscxx . . $ face#num_verts.; i++) { |
| 203 | g3_RotatePointcxx . . $ g3_RotatePoint(fd2e8930c920e2b9).(&World_point_buffercxx . . $ World_point_buffer.[fp->face_vertscxx . . $ face#face_verts.[i]], &rp->vertscxx . . $ room#verts.[fp->face_vertscxx . . $ face#face_verts.[i]]); |
| 204 | g3_ProjectPointcxx . . $ g3_ProjectPoint(4c7ad40c64d4fb9c).(&World_point_buffercxx . . $ World_point_buffer.[fp->face_vertscxx . . $ face#face_verts.[i]]); |
| 205 | } |
| 206 | |
| 207 | SetupPostrenderRoomcxx . . $ SetupPostrenderRoom(cd8c4e8cd0ee4c38).(rp); |
| 208 | |
| 209 | // Render! |
| 210 | if (change_z) |
| 211 | rend_SetZBufferWriteMaskcxx . . $ rend_SetZBufferWriteMask(d4f767463ce0a6b3).(0); |
| 212 | RenderFacecxx . . $ RenderFace(5c94b6ab436d91cf).(rp, facenum); |
| 213 | |
| 214 | // Render any effects for this face |
| 215 | if (Num_specular_faces_to_rendercxx . . $ Num_specular_faces_to_render. > 0) { |
| 216 | RenderSpecularFacesFlatcxx . . $ RenderSpecularFacesFlat(cd8c4e8cd0ee4c38).(rp); |
| 217 | Num_specular_faces_to_rendercxx . . $ Num_specular_faces_to_render. = 0; |
| 218 | } |
| 219 | |
| 220 | if (Num_fog_faces_to_rendercxx . . $ Num_fog_faces_to_render. > 0) { |
| 221 | RenderFogFacescxx . . $ RenderFogFaces(cd8c4e8cd0ee4c38).(rp); |
| 222 | Num_fog_faces_to_rendercxx . . $ Num_fog_faces_to_render. = 0; |
| 223 | } |
| 224 | |
| 225 | // Restore statelimited setting |
| 226 | StateLimitedcxx . . $ StateLimited. = save_state; |
| 227 | |
| 228 | if (change_z) |
| 229 | rend_SetZBufferWriteMaskcxx . . $ rend_SetZBufferWriteMask(d4f767463ce0a6b3).(1); |
| 230 | } |
| 231 | |
| 232 | // Renders all the objects/viseffects/walls we have in our postrender list |
| 233 | void PostRendercxx . . $ PostRender(d4f767463ce0a6b3).(int roomnum) { |
| 234 | g3_GetViewPositioncxx . . $ g3_GetViewPosition(ec8cf6451c36d470).(&Viewer_eyecxx . . $ Viewer_eye.); |
| 235 | g3_GetUnscaledMatrixcxx . . $ g3_GetUnscaledMatrix(dca75c48c9ab5b54).(&Viewer_orientcxx . . $ Viewer_orient.); |
| 236 | |
| 237 | Viewer_roomnumcxx . . $ Viewer_roomnum. = roomnum; |
| 238 | |
| 239 | int i, index; |
| 240 | // Sort the objects |
| 241 | SortPostrenderscxx . . $ SortPostrenders(49f6e7a06ebc5aa8).(); |
| 242 | // qsort(Postrender_list,Num_postrenders,sizeof(*Postrender_list),(int (cdecl *)(const void*,const |
| 243 | // void*))Postrender_sort_func); |
| 244 | |
| 245 | for (i = Num_postrenderscxx . . $ Num_postrenders. - 1; i >= 0; i--) { |
| 246 | |
| 247 | if (Postrender_listcxx . . $ Postrender_list.[i].typecxx . . $ postrender_struct#type. == PRT_VISEFFECTcxx . . $ `Descent3/postrender.h:25:9`!) { |
| 248 | index = Postrender_listcxx . . $ Postrender_list.[i].visnumcxx . . $ postrender_struct#$anonymous_type_0#visnum.; |
| 249 | DrawVisEffectcxx . . $ DrawVisEffect(6089e83781d51a35).(&VisEffectscxx . . $ VisEffects.[index]); |
| 250 | } else if (Postrender_listcxx . . $ Postrender_list.[i].typecxx . . $ postrender_struct#type. == PRT_OBJECTcxx . . $ `Descent3/postrender.h:24:9`!) { |
| 251 | objectcxx . . $ object# *objp = &Objectscxx . . $ Objects.[Postrender_listcxx . . $ Postrender_list.[i].objnumcxx . . $ postrender_struct#$anonymous_type_0#objnum.]; |
| 252 | |
| 253 | if (!OBJECT_OUTSIDEcxx . . $ `lib/object_external_struct.h:130:9`!(&Objects[Postrender_list[i].objnum])) |
| 254 | SetupPostrenderRoomcxx . . $ SetupPostrenderRoom(cd8c4e8cd0ee4c38).(&Roomscxx . . $ Rooms.[Objectscxx . . $ Objects.[Postrender_listcxx . . $ Postrender_list.[i].objnumcxx . . $ postrender_struct#$anonymous_type_0#objnum.].roomnumcxx . . $ object#roomnum.]); |
| 255 | RenderObjectcxx . . $ RenderObject(419c470199a90a97).(objp); |
| 256 | } else { |
| 257 | // Do room face |
| 258 | DrawPostrenderFacecxx . . $ DrawPostrenderFace(6908015b96d379c0).(Postrender_listcxx . . $ Postrender_list.[i].roomnumcxx . . $ postrender_struct#roomnum., Postrender_listcxx . . $ Postrender_list.[i].facenumcxx . . $ postrender_struct#$anonymous_type_0#facenum.); |
| 259 | } |
| 260 | } |
| 261 | Num_postrenderscxx . . $ Num_postrenders. = 0; |
| 262 | rend_SetFogStatecxx . . $ rend_SetFogState(4af4fd0e2b26c4ac).(0); |
| 263 | RenderLightGlowscxx . . $ RenderLightGlows(49f6e7a06ebc5aa8).(); |
| 264 | } |