Debian Codegraph @

common/main/morph.h

raw
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 morph.c
23 *
24 */
25
26 #pragma once
27
28 #ifdef __cplusplus
29 #include <cstdint>
30 #include "dxxsconf.h"
31 #include "vecmat.h"
32 #include "pack.h"
33 #include "polyobj.h"
34 #include "dsx-ns.h"
35
36 #ifdef DXX_BUILD_DESCENT
37 #include "object.h"
38 #include <array>
39 #include <memory>
40 #include <new>
41 #include <span>
42
43 namespace dcx {
44
45 struct morph_data : prohibit_void_ptr<morph_data>
46 {
47 using ptr = std::unique_ptr<morph_data>;
48 enum
49 {
50 MAX_VECS = 5000u,
51 };
52 enum class max_vectors : std::size_t
53 {
54 };
55 static void *operator new(std::size_t bytes) = delete; /* require caller to use placement-form to specify the number of vectors to allocate */
56 static void operator delete(void *p)
57 {
58 ::operator delete(p);
59 }
60 static void operator delete(void *p, max_vectors)
61 {
62 ::operator delete(p);
63 }
64 enum class submodel_state : uint8_t
65 {
66 invisible,
67 animating,
68 visible,
69 };
70 object_base *const obj; // object which is morphing
71 const object_signature_t Morph_sig;
72 typename object_base::control_type morph_save_control_type;
73 typename object_base::movement_type morph_save_movement_type;
74 uint8_t n_submodels_active;
75 std::array<submodel_state, MAX_SUBMODELS> submodel_active; // which submodels are active
76 const max_vectors max_vecs;
77 physics_info morph_save_phys_info;
78 std::array<int, MAX_SUBMODELS>
79 n_morphing_points, // how many active points in each part
80 submodel_startpoints; // first point for each submodel
81 static ptr create(object_base &, const polymodel &, polygon_model_index);
82 std::span<fix> get_morph_times();
83 std::span<vms_vector> get_morph_vecs();
84 std::span<vms_vector> get_morph_deltas();
85 private:
86 /* Advise gcc to inline this `operator new` because if it is not inline,
87 * then -Wmismatched-new-delete issues a spurious warning when it inlines
88 * the body of `operator delete(void *, max_vectors)` and does not inline
89 * this method. Possibly relevant gcc bug reports:
90 *
91 * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100485 `False positive in -Wmismatched-new-delete`
92 * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103993 `-Wismatched-new-delete due to difference in inlining decisions`
93 */
94 static inline void *operator new(std::size_t bytes, max_vectors);
95 explicit morph_data(object_base &o, max_vectors);
96 };
97
98 struct d_level_unique_morph_object_state;
99
100 morph_data::ptr *find_morph_data(d_level_unique_morph_object_state &LevelUniqueMorphObjectState, object_base &obj);
101 }
102
103 namespace dsx {
104 void morph_start(d_level_unique_morph_object_state &, d_level_shared_polygon_model_state &, object_base &obj);
105
106 //process the morphing object for one frame
107 void do_morph_frame(object &obj);
108
109 //called at the start of a level
110 void init_morphs(d_level_unique_morph_object_state &MorphObjectState);
111 }
112 #endif
113
114 #endif