| 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 polyobj.c, the polygon object code |
| 23 |
* |
| 24 |
*/ |
| 25 |
|
| 26 |
#pragma once |
| 27 |
|
| 28 |
#include "fwd-piggy.h" |
| 29 |
#include "vecmat.h" |
| 30 |
#include "3d.h" |
| 31 |
#include <cstddef> |
| 32 |
#include <cstdint> |
| 33 |
#include <memory> |
| 34 |
#include "d_array.h" |
| 35 |
#include "inferno.h" |
| 36 |
#include "pack.h" |
| 37 |
#include "physfsx.h" |
| 38 |
|
| 39 |
namespace dcx { |
| 40 |
|
| 41 |
enum class polygon_simpler_model_index : uint8_t |
| 42 |
{ |
| 43 |
None = 0, |
| 44 |
}; |
| 45 |
|
| 46 |
} |
| 47 |
|
| 48 |
#ifdef DXX_BUILD_DESCENT |
| 49 |
namespace dsx { |
| 50 |
|
| 51 |
enum class polygon_model_index : uint8_t |
| 52 |
{ |
| 53 |
None = UINT8_MAX |
| 54 |
}; |
| 55 |
|
| 56 |
constexpr std::size_t MAX_POLYGON_MODELS{+ |
| 57 |
#if DXX_BUILD_DESCENT == 1 |
| 58 |
85 |
| 59 |
#elif DXX_BUILD_DESCENT == 2 |
| 60 |
200 |
| 61 |
#endif |
| 62 |
}; |
| 63 |
|
| 64 |
struct robot_info; |
| 65 |
struct glow_values_t; |
| 66 |
|
| 67 |
//for each model, a model number for dying & dead variants, or polygon_model_index::None if none |
| 68 |
extern enumerated_array<polygon_model_index, MAX_POLYGON_MODELS, polygon_model_index> Dying_modelnums, Dead_modelnums; |
| 69 |
} |
| 70 |
#endif |
| 71 |
|
| 72 |
namespace dcx { |
| 73 |
|
| 74 |
constexpr std::size_t MAX_SUBMODELS{10}; |
| 75 |
enum class submodel_index : uint8_t |
| 76 |
{ |
| 77 |
/* Valid values are [0 .. (MAX_SUBMODELS - 1)]. */ |
| 78 |
}; |
| 79 |
|
| 80 |
//used to describe a polygon model |
| 81 |
struct polymodel : prohibit_void_ptr<polymodel> |
| 82 |
{ |
| 83 |
unsigned n_models; |
| 84 |
unsigned model_data_size; |
| 85 |
std::unique_ptr<uint8_t[]> model_data; |
| 86 |
std::array<int, MAX_SUBMODELS> submodel_ptrs; |
| 87 |
std::array<vms_vector, MAX_SUBMODELS> submodel_offsets; |
| 88 |
std::array<vms_vector, MAX_SUBMODELS> submodel_norms; // norm for sep plane |
| 89 |
std::array<vms_vector, MAX_SUBMODELS> submodel_pnts; // point on sep plane |
| 90 |
enumerated_array<fix, MAX_SUBMODELS, submodel_index> submodel_rads; // radius for each submodel |
| 91 |
std::array<ubyte, MAX_SUBMODELS> submodel_parents; // what is parent for each submodel |
| 92 |
std::array<vms_vector, MAX_SUBMODELS> submodel_mins; |
| 93 |
std::array<vms_vector, MAX_SUBMODELS> submodel_maxs; |
| 94 |
vms_vector mins,maxs; // min,max for whole model |
| 95 |
fix rad; |
| 96 |
ushort first_texture; |
| 97 |
ubyte n_textures; |
| 98 |
polygon_simpler_model_index simpler_model; // alternate model with less detail (0 if none, model_num+1 else) |
| 99 |
//vms_vector min,max; |
| 100 |
}; |
| 101 |
|
| 102 |
class submodel_angles |
| 103 |
{ |
| 104 |
using array_type = const std::array<vms_angvec, MAX_SUBMODELS>; |
| 105 |
array_type *p{}; |
| 106 |
public: |
| 107 |
submodel_angles(std::nullptr_t) : p{nullptr} {} |
| 108 |
submodel_angles(array_type &a) : p{&a} {} |
| 109 |
explicit operator bool() const { return p != nullptr; } |
| 110 |
typename array_type::const_reference operator[](std::size_t i) const |
| 111 |
{ |
| 112 |
array_type &a = *p; |
| 113 |
return a[i]; |
| 114 |
} |
| 115 |
}; |
| 116 |
|
| 117 |
struct d_level_shared_polygon_model_state |
| 118 |
{ |
| 119 |
// how many polygon objects there are |
| 120 |
unsigned N_polygon_models; |
| 121 |
}; |
| 122 |
|
| 123 |
void init_polygon_models(d_level_shared_polygon_model_state &); |
| 124 |
|
| 125 |
/* Only defined if DXX_WORDS_NEED_ALIGNMENT, but always declared, so |
| 126 |
* that the header preprocesses to the same text regardless of the |
| 127 |
* setting. |
| 128 |
*/ |
| 129 |
void align_polygon_model_data(polymodel *pm); |
| 130 |
|
| 131 |
} |
| 132 |
#ifdef DXX_BUILD_DESCENT |
| 133 |
namespace dsx { |
| 134 |
|
| 135 |
/* Individual levels can customize the polygon models through robot overrides, |
| 136 |
* so this must be scoped to the level, not to the mission. |
| 137 |
*/ |
| 138 |
struct d_level_shared_polygon_model_state : ::dcx::d_level_shared_polygon_model_state |
| 139 |
{ |
| 140 |
enumerated_array<polymodel, MAX_POLYGON_MODELS, polygon_model_index> Polygon_models; |
| 141 |
// array of names of currently-loaded models |
| 142 |
enumerated_array<char[FILENAME_LEN], MAX_POLYGON_MODELS, polygon_model_index> Pof_names; |
| 143 |
#if DXX_BUILD_DESCENT == 2 |
| 144 |
//the model number of the marker object |
| 145 |
polygon_model_index Marker_model_num = polygon_model_index::None; |
| 146 |
bool Exit_models_loaded; |
| 147 |
#endif |
| 148 |
}; |
| 149 |
|
| 150 |
// array of pointers to polygon objects |
| 151 |
extern d_level_shared_polygon_model_state LevelSharedPolygonModelState; |
| 152 |
|
| 153 |
void free_polygon_models(d_level_shared_polygon_model_state &LevelSharedPolygonModelState); |
| 154 |
|
| 155 |
polygon_model_index load_polygon_model(const char *filename, int n_textures, int first_texture, robot_info *r); |
| 156 |
} |
| 157 |
#endif |
| 158 |
|
| 159 |
namespace dcx { |
| 160 |
|
| 161 |
class alternate_textures |
| 162 |
{ |
| 163 |
std::span<const bitmap_index> p{}; |
| 164 |
public: |
| 165 |
constexpr alternate_textures() = default; |
| 166 |
template <std::size_t N> |
| 167 |
constexpr alternate_textures(const std::array<bitmap_index, N> &a) : |
| 168 |
p{a} |
| 169 |
{ |
| 170 |
} |
| 171 |
constexpr operator std::span<const bitmap_index>() const { return p; } |
| 172 |
}; |
| 173 |
|
| 174 |
} |
| 175 |
|
| 176 |
#ifdef DXX_BUILD_DESCENT |
| 177 |
namespace dsx { |
| 178 |
// draw a polygon model |
| 179 |
void draw_polygon_model(const enumerated_array<polymodel, MAX_POLYGON_MODELS, polygon_model_index> &, grs_canvas &, tmap_drawer_type tmap_drawer_ptr, const vms_vector &pos, const vms_matrix &orient, submodel_angles anim_angles, const polygon_model_index model_num, unsigned flags, g3s_lrgb light, const glow_values_t *glow_values, alternate_textures); |
| 180 |
void draw_polygon_model(grs_canvas &, tmap_drawer_type tmap_drawer_ptr, const vms_vector &pos, const vms_matrix &orient, submodel_angles anim_angles, const polymodel &model_num, unsigned flags, g3s_lrgb light, const glow_values_t *glow_values, alternate_textures); |
| 181 |
} |
| 182 |
#endif |
| 183 |
|
| 184 |
// draws the given model in the current canvas. The distance is set to |
| 185 |
// more-or-less fill the canvas. Note that this routine actually renders |
| 186 |
// into an off-screen canvas that it creates, then copies to the current |
| 187 |
// canvas. |
| 188 |
void draw_model_picture(grs_canvas &, const polymodel &mn, const vms_angvec &orient_angles); |
| 189 |
|
| 190 |
#ifdef DXX_BUILD_DESCENT |
| 191 |
#if DXX_BUILD_DESCENT == 1 |
| 192 |
#define MAX_POLYOBJ_TEXTURES 50 |
| 193 |
#elif DXX_BUILD_DESCENT == 2 |
| 194 |
|
| 195 |
#define MAX_POLYOBJ_TEXTURES 100 |
| 196 |
constexpr std::integral_constant<unsigned, 166> N_D2_POLYGON_MODELS{}; |
| 197 |
#endif |
| 198 |
#endif |
| 199 |
|
| 200 |
namespace dcx { |
| 201 |
|
| 202 |
#ifdef DXX_BUILD_DESCENT |
| 203 |
#if DXX_BUILD_DESCENT == 2 |
| 204 |
/* This function exists in both games and has the same implementation in |
| 205 |
* both, but is static in Descent 1. Declare it in the header only for |
| 206 |
* Descent 2. |
| 207 |
*/ |
| 208 |
// free up a model, getting rid of all its memory |
| 209 |
void free_model(polymodel &po); |
| 210 |
#endif |
| 211 |
#endif |
| 212 |
|
| 213 |
/* |
| 214 |
* reads a polymodel structure from a PHYSFS_File |
| 215 |
*/ |
| 216 |
void polymodel_read(polymodel &pm, NamedPHYSFS_File fp); |
| 217 |
} |
| 218 |
#if 0 |
| 219 |
void polymodel_write(PHYSFS_File *fp, const polymodel &pm); |
| 220 |
#endif |
| 221 |
|
| 222 |
/* |
| 223 |
* routine which allocates, reads, and inits a polymodel's model_data |
| 224 |
*/ |
| 225 |
#ifdef DXX_BUILD_DESCENT |
| 226 |
namespace dsx { |
| 227 |
void polygon_model_data_read(polymodel *pm, PHYSFS_File *fp); |
| 228 |
polygon_model_index build_polygon_model_index_from_untrusted(unsigned i); |
| 229 |
#if DXX_USE_OGL |
| 230 |
void ogl_cache_polymodel_textures(polygon_model_index model_num); |
| 231 |
#endif |
| 232 |
} |
| 233 |
#endif |