| 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 | #include "pstypes.h"cxx . . $ `<file>/lib/pstypes.h`/ |
| 20 | |
| 21 | #include "special_face.h"cxx . . $ `<file>/Descent3/special_face.h`/ |
| 22 | #include "mono.h"cxx . . $ `<file>/ddebug/mono.h`/ |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
| 25 | #include "mem.h"cxx . . $ `<file>/mem/mem.h`/ |
| 26 | |
| 27 | int Num_of_special_facescxx . . $ Num_of_special_faces. = 0; |
| 28 | special_facecxx . . $ special_face# SpecialFacescxx . . $ SpecialFaces.[MAX_SPECIAL_FACEScxx . . $ `Descent3/special_face.h:27:9`!]; |
| 29 | |
| 30 | static uint16_tcxx . . $ uint16_t# Free_special_face_listcxx . . $ Free_special_face_list.[MAX_SPECIAL_FACEScxx . . $ `Descent3/special_face.h:27:9`!]; |
| 31 | |
| 32 | // Sets all the special faces to unused |
| 33 | void InitSpecialFacescxx . . $ InitSpecialFaces(49f6e7a06ebc5aa8).() { |
| 34 | int i; |
| 35 | |
| 36 | for (i = 0; i < MAX_SPECIAL_FACEScxx . . $ `Descent3/special_face.h:27:9`!; i++) { |
| 37 | SpecialFacescxx . . $ SpecialFaces.[i].usedcxx . . $ special_face#used. = 0; |
| 38 | SpecialFacescxx . . $ SpecialFaces.[i].vertnormscxx . . $ special_face#vertnorms. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 39 | SpecialFacescxx . . $ SpecialFaces.[i].spec_instancecxx . . $ special_face#spec_instance. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 40 | Free_special_face_listcxx . . $ Free_special_face_list.[i] = i; |
| 41 | } |
| 42 | } |
| 43 | // Returns an index into the special faces array |
| 44 | int AllocSpecialFacecxx . . $ AllocSpecialFace(728d02a8a18fc883).(int type, int num, bool vertnorms, int num_vertnorms) { |
| 45 | int n; |
| 46 | |
| 47 | if (Num_of_special_facescxx . . $ Num_of_special_faces. >= MAX_SPECIAL_FACEScxx . . $ `Descent3/special_face.h:27:9`!) { |
| 48 | Int3cxx . . $ `misc/pserror.h:247:9`!(); // Get Jason, ran out of special faces! |
| 49 | return BAD_SPECIAL_FACE_INDEXcxx . . $ `Descent3/special_face.h:26:9`!; |
| 50 | } |
| 51 | |
| 52 | n = Free_special_face_listcxx . . $ Free_special_face_list.[Num_of_special_facescxx . . $ Num_of_special_faces.++]; |
| 53 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(SpecialFaces[n].used == 0); |
| 54 | |
| 55 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(n >= 0 && n < MAX_SPECIAL_FACEScxx . . $ `Descent3/special_face.h:27:9`!); |
| 56 | |
| 57 | memset(&SpecialFacescxx . . $ SpecialFaces.[n], 0, sizeof(special_facecxx . . $ special_face#)); |
| 58 | |
| 59 | SpecialFacescxx . . $ SpecialFaces.[n].spec_instancecxx . . $ special_face#spec_instance. = (specular_instancecxx . . $ specular_instance# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(num * sizeof(specular_instance)); |
| 60 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(SpecialFaces[n].spec_instance); |
| 61 | |
| 62 | SpecialFacescxx . . $ SpecialFaces.[n].typecxx . . $ special_face#type. = type; |
| 63 | SpecialFacescxx . . $ SpecialFaces.[n].numcxx . . $ special_face#num. = num; |
| 64 | SpecialFacescxx . . $ SpecialFaces.[n].flagscxx . . $ special_face#flags. = 0; |
| 65 | SpecialFacescxx . . $ SpecialFaces.[n].usedcxx . . $ special_face#used. = 1; |
| 66 | |
| 67 | if (vertnorms) { |
| 68 | SpecialFacescxx . . $ SpecialFaces.[n].vertnormscxx . . $ special_face#vertnorms. = (vectorcxx . . $ vector# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(num_vertnorms * sizeof(vector)); |
| 69 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(SpecialFaces[n].vertnorms); |
| 70 | SpecialFacescxx . . $ SpecialFaces.[n].flagscxx . . $ special_face#flags. |= SFF_SPEC_SMOOTHcxx . . $ `Descent3/special_face.h:38:9`!; |
| 71 | } |
| 72 | |
| 73 | return n; |
| 74 | } |
| 75 | |
| 76 | // Given a handle, frees the special face |
| 77 | void FreeSpecialFacecxx . . $ FreeSpecialFace(d4f767463ce0a6b3).(int handle) { |
| 78 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(handle >= 0 && handle <= MAX_SPECIAL_FACEScxx . . $ `Descent3/special_face.h:27:9`!); |
| 79 | |
| 80 | if (SpecialFacescxx . . $ SpecialFaces.[handle].usedcxx . . $ special_face#used. < 1) |
| 81 | return; |
| 82 | |
| 83 | SpecialFacescxx . . $ SpecialFaces.[handle].usedcxx . . $ special_face#used.--; |
| 84 | |
| 85 | if (SpecialFacescxx . . $ SpecialFaces.[handle].usedcxx . . $ special_face#used. == 0) { |
| 86 | Free_special_face_listcxx . . $ Free_special_face_list.[--Num_of_special_facescxx . . $ Num_of_special_faces.] = handle; |
| 87 | if (SpecialFacescxx . . $ SpecialFaces.[handle].spec_instancecxx . . $ special_face#spec_instance.) { |
| 88 | mem_freecxx . . $ `mem/mem.h:80:9`!(SpecialFaces[handle].spec_instance); |
| 89 | SpecialFacescxx . . $ SpecialFaces.[handle].spec_instancecxx . . $ special_face#spec_instance. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 90 | } |
| 91 | |
| 92 | if (SpecialFacescxx . . $ SpecialFaces.[handle].vertnormscxx . . $ special_face#vertnorms.) { |
| 93 | mem_freecxx . . $ `mem/mem.h:80:9`!(SpecialFaces[handle].vertnorms); |
| 94 | SpecialFacescxx . . $ SpecialFaces.[handle].vertnormscxx . . $ special_face#vertnorms. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 95 | } |
| 96 | } |
| 97 | } |