Subversion Repositories Games.Descent

Rev

Blame | Last modification | View Log | Download | RSS feed

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