| 1 | /* |
| 2 | * Portions of this file are copyright Rebirth contributors and licensed as |
| 3 | * described in COPYING.txt. |
| 4 | * Portions of this file are copyright Parallax Software and licensed |
| 5 | * according to the Parallax license below. |
| 6 | * See COPYING.txt for license details. |
| 7 | |
| 8 | THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX |
| 9 | SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO |
| 10 | END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A |
| 11 | ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS |
| 12 | IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS |
| 13 | SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE |
| 14 | FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE |
| 15 | CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS |
| 16 | AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. |
| 17 | COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * |
| 22 | * Header for fvi.c |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #pragma once |
| 27 | |
| 28 | #include "dsx-ns.h" |
| 29 | #include "vecmat.h" |
| 30 | |
| 31 | #include "object.h" |
| 32 | #include "pack.h" |
| 33 | #include "countarray.h" |
| 34 | #include "fwd-segment.h" |
| 35 | #include "robot.h" |
| 36 | |
| 37 | //return values for find_vector_intersection() - what did we hit? |
| 38 | enum class fvi_hit_type : uint8_t |
| 39 | { |
| 40 | None, //we hit nothing |
| 41 | Wall, //we hit a wall |
| 42 | Object, //we hit an object - which one? no way to tell... |
| 43 | BadP0, //start point not is specified segment |
| 44 | }; |
| 45 | |
| 46 | #define MAX_FVI_SEGS 100 |
| 47 | |
| 48 | //this data structure gets filled in by find_vector_intersection() |
| 49 | struct fvi_info : prohibit_void_ptr<fvi_info> |
| 50 | { |
| 51 | struct segment_array_t : public count_array_t<segnum_t, MAX_FVI_SEGS> {}; |
| 52 | vms_vector hit_pnt; //where we hit |
| 53 | segnum_t hit_seg; //what segment hit_pnt is in |
| 54 | sidenum_t hit_side; //if hit wall, which side |
| 55 | segnum_t hit_side_seg; //what segment the hit side is in |
| 56 | objnum_t hit_object; //if object hit, which object |
| 57 | vms_vector hit_wallnorm; //if hit wall, ptr to its surface normal |
| 58 | segment_array_t seglist; |
| 59 | }; |
| 60 | |
| 61 | //flags for fvi query |
| 62 | #define FQ_TRANSWALL 2 //go through transparent walls |
| 63 | #define FQ_TRANSPOINT 4 //go through trans wall if hit point is transparent |
| 64 | #define FQ_GET_SEGLIST 8 //build a list of segments |
| 65 | #define FQ_IGNORE_POWERUPS 16 //ignore powerups |
| 66 | |
| 67 | #ifdef DXX_BUILD_DESCENT |
| 68 | namespace dcx { |
| 69 | struct fvi_hitpoint |
| 70 | { |
| 71 | fix u, v; |
| 72 | }; |
| 73 | |
| 74 | struct sphere_intersects_wall_result |
| 75 | { |
| 76 | const shared_segment *seg; |
| 77 | sidenum_t side; |
| 78 | }; |
| 79 | |
| 80 | } |
| 81 | |
| 82 | namespace dsx { |
| 83 | |
| 84 | //this data contains the parms to fvi() |
| 85 | struct fvi_query |
| 86 | { |
| 87 | static constexpr const std::ranges::subrange<const vcobjidx_t *> unused_ignore_obj_list{}; |
| 88 | static constexpr const d_level_unique_object_state *const unused_LevelUniqueObjectState{nullptr}; |
| 89 | static constexpr const d_robot_info_array *const unused_Robot_info{nullptr}; |
| 90 | const vms_vector &p0; |
| 91 | const vms_vector &p1; |
| 92 | const std::ranges::subrange<const vcobjidx_t *> ignore_obj_list; |
| 93 | const d_level_unique_object_state *const LevelUniqueObjectState; |
| 94 | /* This member is required when LevelUniqueObjectState != nullptr and |
| 95 | * thisobjnum->type == OBJ_ROBOT. |
| 96 | * Otherwise, it is ignored. |
| 97 | */ |
| 98 | const d_robot_info_array *const Robot_info; |
| 99 | const int flags; |
| 100 | /* This member depends on the value of LevelUniqueObjectState. |
| 101 | * If LevelUniqueObjectState != nullptr, then `thisobjnum` _must_ be a |
| 102 | * valid object. It will be dereferenced in the course of comparing to |
| 103 | * objects in the segment. |
| 104 | * |
| 105 | * If LevelUniqueObjectState == nullptr, then `thisobjnum` may be a valid |
| 106 | * object, or not, depending on the caller's needs. |
| 107 | * |
| 108 | * If `thisobjnum` is a valid object, then regardless of whether |
| 109 | * LevelUniqueObjectState == nullptr: |
| 110 | * - fvi_sub enables the zero-radius hack for objects that ignore wall |
| 111 | * collisions |
| 112 | * - fvi_sub respects the ghostphysics cheat if `thisobjnum` is the local |
| 113 | * player |
| 114 | */ |
| 115 | const icobjptridx_t thisobjnum; |
| 116 | }; |
| 117 | |
| 118 | //Find out if a vector intersects with anything. |
| 119 | //Fills in hit_data, an fvi_info structure (see above). |
| 120 | //Parms: |
| 121 | // p0 & startseg describe the start of the vector |
| 122 | // p1 the end of the vector |
| 123 | // rad the radius of the cylinder |
| 124 | // thisobjnum used to prevent an object with colliding with itself |
| 125 | // ingore_obj_list NULL, or ptr to a list of objnums to ignore, terminated with -1 |
| 126 | // check_obj_flag determines whether collisions with objects are checked |
| 127 | //Returns the hit_data->hit_type |
| 128 | // Pass fvi_query by value since callers construct an anonymous instance solely |
| 129 | // for this call. Passing it by value avoids an extra indirection in the |
| 130 | // called function, and has no cost since it is constructed in place. |
| 131 | [[nodiscard]] |
| 132 | fvi_hit_type find_vector_intersection(fvi_query fq, segnum_t startseg, fix rad, fvi_info &hit_data); |
| 133 | |
| 134 | //finds the uv coords of the given point on the given seg & side |
| 135 | //fills in u & v. if l is non-NULL fills it in also |
| 136 | [[nodiscard]] |
| 137 | fvi_hitpoint find_hitpoint_uv(const vms_vector &pnt, const cscusegment seg, sidenum_t sidenum, uint_fast32_t facenum); |
| 138 | } |
| 139 | |
| 140 | //Returns true if the object is through any walls |
| 141 | sphere_intersects_wall_result sphere_intersects_wall(fvcsegptridx &vcsegptridx, fvcvertptr &vcvertptr, const vms_vector &pnt, vcsegptridx_t seg, fix rad); |
| 142 | #endif |