Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | pmbaty | 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. |
||
| 6 | * See COPYING.txt for license details. |
||
| 7 | */ |
||
| 8 | |||
| 9 | #pragma once |
||
| 10 | |||
| 11 | #include <type_traits> |
||
| 12 | #include "dxxsconf.h" |
||
| 13 | #include "dsx-ns.h" |
||
| 14 | #include "objnum.h" |
||
| 15 | #include "fwd-vecmat.h" |
||
| 16 | #include "fwd-segment.h" |
||
| 17 | #include "fwd-window.h" |
||
| 18 | #include "fwd-valptridx.h" |
||
| 19 | #include <array> |
||
| 20 | |||
| 21 | struct bitmap_index; |
||
| 22 | |||
| 23 | namespace dcx { |
||
| 24 | |||
| 25 | // Movement types |
||
| 26 | enum movement_type_t : uint8_t; |
||
| 27 | constexpr std::integral_constant<std::size_t, 350> MAX_OBJECTS{}; |
||
| 28 | constexpr std::integral_constant<std::size_t, MAX_OBJECTS - 20> MAX_USED_OBJECTS{}; |
||
| 29 | struct d_level_unique_control_center_state; |
||
| 30 | |||
| 31 | // Render types |
||
| 32 | enum render_type_t : uint8_t; |
||
| 33 | |||
| 34 | } |
||
| 35 | |||
| 36 | #ifdef dsx |
||
| 37 | namespace dsx { |
||
| 38 | struct object; |
||
| 39 | struct d_level_unique_object_state; |
||
| 40 | } |
||
| 41 | DXX_VALPTRIDX_DECLARE_SUBTYPE(dsx::, object, objnum_t, MAX_OBJECTS); |
||
| 42 | |||
| 43 | namespace dsx { |
||
| 44 | DXX_VALPTRIDX_DEFINE_SUBTYPE_TYPEDEFS(object, obj); |
||
| 45 | |||
| 46 | static constexpr valptridx<object>::magic_constant<0xffff> object_none{}; |
||
| 47 | static constexpr valptridx<object>::magic_constant<0> object_first{}; |
||
| 48 | |||
| 49 | #if defined(DXX_BUILD_DESCENT_I) |
||
| 50 | constexpr std::integral_constant<unsigned, 15> MAX_OBJECT_TYPES{}; |
||
| 51 | #elif defined(DXX_BUILD_DESCENT_II) |
||
| 52 | constexpr std::integral_constant<unsigned, 16> MAX_OBJECT_TYPES{}; |
||
| 53 | struct d_level_unique_control_center_state; |
||
| 54 | #endif |
||
| 55 | |||
| 56 | } |
||
| 57 | #endif |
||
| 58 | |||
| 59 | // Result types |
||
| 60 | typedef unsigned result_type_t; |
||
| 61 | constexpr std::integral_constant<result_type_t, 0> RESULT_NOTHING{}; // Ignore this collision |
||
| 62 | constexpr std::integral_constant<result_type_t, 1> RESULT_CHECK{}; // Check for this collision |
||
| 63 | |||
| 64 | // Control types - what tells this object what do do |
||
| 65 | typedef unsigned control_type_t; |
||
| 66 | constexpr std::integral_constant<control_type_t, 0> CT_NONE{}; // doesn't move (or change movement) |
||
| 67 | constexpr std::integral_constant<control_type_t, 1> CT_AI{}; // driven by AI |
||
| 68 | constexpr std::integral_constant<control_type_t, 2> CT_EXPLOSION{}; // explosion sequencer |
||
| 69 | constexpr std::integral_constant<control_type_t, 4> CT_FLYING{}; // the player is flying |
||
| 70 | constexpr std::integral_constant<control_type_t, 5> CT_SLEW{}; // slewing |
||
| 71 | constexpr std::integral_constant<control_type_t, 6> CT_FLYTHROUGH{}; // the flythrough system |
||
| 72 | constexpr std::integral_constant<control_type_t, 9> CT_WEAPON{}; // laser, etc. |
||
| 73 | constexpr std::integral_constant<control_type_t, 10> CT_REPAIRCEN{}; // under the control of the repair center |
||
| 74 | constexpr std::integral_constant<control_type_t, 11> CT_MORPH{}; // this object is being morphed |
||
| 75 | constexpr std::integral_constant<control_type_t, 12> CT_DEBRIS{}; // this is a piece of debris |
||
| 76 | constexpr std::integral_constant<control_type_t, 13> CT_POWERUP{}; // animating powerup blob |
||
| 77 | constexpr std::integral_constant<control_type_t, 14> CT_LIGHT{}; // doesn't actually do anything |
||
| 78 | constexpr std::integral_constant<control_type_t, 15> CT_REMOTE{}; // controlled by another net player |
||
| 79 | constexpr std::integral_constant<control_type_t, 16> CT_CNTRLCEN{}; // the control center/main reactor |
||
| 80 | |||
| 81 | // misc object flags |
||
| 82 | typedef unsigned object_flag_t; |
||
| 83 | constexpr std::integral_constant<object_flag_t, 1> OF_EXPLODING{}; // this object is exploding |
||
| 84 | constexpr std::integral_constant<object_flag_t, 2> OF_SHOULD_BE_DEAD{}; // this object should be dead, so next time we can, we should delete this object. |
||
| 85 | constexpr std::integral_constant<object_flag_t, 4> OF_DESTROYED{}; // this has been killed, and is showing the dead version |
||
| 86 | constexpr std::integral_constant<object_flag_t, 8> OF_SILENT{}; // this makes no sound when it hits a wall. Added by MK for weapons, if you extend it to other types, do it completely! |
||
| 87 | constexpr std::integral_constant<object_flag_t, 16> OF_ATTACHED{}; // this object is a fireball attached to another object |
||
| 88 | #if defined(DXX_BUILD_DESCENT_II) |
||
| 89 | constexpr std::integral_constant<object_flag_t, 64> OF_PLAYER_DROPPED{}; // this object was dropped by the player... |
||
| 90 | #endif |
||
| 91 | |||
| 92 | // physics flags |
||
| 93 | typedef unsigned physics_flag_t; |
||
| 94 | constexpr std::integral_constant<physics_flag_t, 0x01> PF_TURNROLL{}; // roll when turning |
||
| 95 | constexpr std::integral_constant<physics_flag_t, 0x02> PF_LEVELLING{}; // level object with closest side |
||
| 96 | constexpr std::integral_constant<physics_flag_t, 0x04> PF_BOUNCE{}; // bounce (not slide) when hit will |
||
| 97 | constexpr std::integral_constant<physics_flag_t, 0x08> PF_WIGGLE{}; // wiggle while flying |
||
| 98 | constexpr std::integral_constant<physics_flag_t, 0x10> PF_STICK{}; // object sticks (stops moving) when hits wall |
||
| 99 | constexpr std::integral_constant<physics_flag_t, 0x20> PF_PERSISTENT{}; // object keeps going even after it hits another object (eg, fusion cannon) |
||
| 100 | constexpr std::integral_constant<physics_flag_t, 0x40> PF_USES_THRUST{}; // this object uses its thrust |
||
| 101 | #if defined(DXX_BUILD_DESCENT_II) |
||
| 102 | constexpr std::integral_constant<physics_flag_t, 0x80> PF_BOUNCED_ONCE{}; // Weapon has bounced once. |
||
| 103 | constexpr std::integral_constant<physics_flag_t, 0x100> PF_FREE_SPINNING{}; // Drag does not apply to rotation of this object |
||
| 104 | constexpr std::integral_constant<physics_flag_t, 0x200> PF_BOUNCES_TWICE{}; // This weapon bounces twice, then dies |
||
| 105 | #endif |
||
| 106 | |||
| 107 | namespace dcx { |
||
| 108 | enum object_type_t : uint8_t; |
||
| 109 | struct object_base; |
||
| 110 | |||
| 111 | typedef unsigned powerup_flag_t; |
||
| 112 | constexpr std::integral_constant<powerup_flag_t, 1> PF_SPAT_BY_PLAYER{}; //this powerup was spat by the player |
||
| 113 | |||
| 114 | constexpr std::integral_constant<unsigned, 0x3fffffff> IMMORTAL_TIME{}; // Time assigned to immortal objects, about 32768 seconds, or about 9 hours. |
||
| 115 | |||
| 116 | struct shortpos; |
||
| 117 | struct quaternionpos; |
||
| 118 | |||
| 119 | // This is specific to the shortpos extraction routines in gameseg.c. |
||
| 120 | constexpr std::integral_constant<unsigned, 10> RELPOS_PRECISION{}; |
||
| 121 | constexpr std::integral_constant<unsigned, 9> MATRIX_PRECISION{}; |
||
| 122 | |||
| 123 | struct physics_info; |
||
| 124 | struct physics_info_rw; |
||
| 125 | |||
| 126 | struct laser_parent; |
||
| 127 | struct laser_info_rw; |
||
| 128 | |||
| 129 | struct explosion_info; |
||
| 130 | struct explosion_info_rw; |
||
| 131 | |||
| 132 | struct light_info; |
||
| 133 | struct light_info_rw; |
||
| 134 | |||
| 135 | struct powerup_info; |
||
| 136 | |||
| 137 | struct vclip_info; |
||
| 138 | struct vclip_info_rw; |
||
| 139 | |||
| 140 | struct polyobj_info; |
||
| 141 | struct polyobj_info_rw; |
||
| 142 | |||
| 143 | struct obj_position; |
||
| 144 | struct object_rw; |
||
| 145 | |||
| 146 | } |
||
| 147 | |||
| 148 | #ifdef dsx |
||
| 149 | namespace dsx { |
||
| 150 | |||
| 151 | #if defined(DXX_BUILD_DESCENT_I) |
||
| 152 | constexpr std::integral_constant<unsigned, 4> MAX_CONTROLCEN_GUNS{}; |
||
| 153 | #elif defined(DXX_BUILD_DESCENT_II) |
||
| 154 | constexpr std::integral_constant<unsigned, 8> MAX_CONTROLCEN_GUNS{}; |
||
| 155 | struct d_unique_buddy_state; |
||
| 156 | #endif |
||
| 157 | |||
| 158 | struct powerup_info_rw; |
||
| 159 | struct window_rendered_data; |
||
| 160 | struct reactor_static; |
||
| 161 | |||
| 162 | using collision_inner_array_t = std::array<uint8_t, MAX_OBJECT_TYPES>; |
||
| 163 | using collision_outer_array_t = std::array<collision_inner_array_t, MAX_OBJECT_TYPES>; |
||
| 164 | extern const collision_outer_array_t CollisionResult; |
||
| 165 | |||
| 166 | } |
||
| 167 | #endif |
||
| 168 | |||
| 169 | namespace dcx { |
||
| 170 | extern int Object_next_signature; // The next signature for the next newly created object |
||
| 171 | |||
| 172 | extern int Num_robot_types; |
||
| 173 | } |
||
| 174 | |||
| 175 | #ifdef dsx |
||
| 176 | namespace dsx { |
||
| 177 | extern object *ConsoleObject; // pointer to the object that is the player |
||
| 178 | extern const object *Viewer; // which object we are seeing from |
||
| 179 | extern object *Dead_player_camera; |
||
| 180 | } |
||
| 181 | #endif |
||
| 182 | |||
| 183 | enum class player_dead_state : uint8_t |
||
| 184 | { |
||
| 185 | no, |
||
| 186 | yes, |
||
| 187 | exploded, |
||
| 188 | }; |
||
| 189 | |||
| 190 | namespace dcx { |
||
| 191 | extern player_dead_state Player_dead_state; // !0 means player is dead! |
||
| 192 | extern objnum_t Player_fired_laser_this_frame; |
||
| 193 | |||
| 194 | // Draw a blob-type object, like a fireball |
||
| 195 | void draw_object_blob(grs_canvas &, const object_base &obj, bitmap_index bitmap); |
||
| 196 | } |
||
| 197 | |||
| 198 | #ifdef dsx |
||
| 199 | namespace dsx { |
||
| 200 | // do whatever setup needs to be done |
||
| 201 | void init_objects(); |
||
| 202 | |||
| 203 | // when an object has moved into a new segment, this function unlinks it |
||
| 204 | // from its old segment, and links it into the new segment |
||
| 205 | void obj_relink(fvmobjptr &vmobjptr, fvmsegptr &vmsegptr, vmobjptridx_t objnum, vmsegptridx_t newsegnum); |
||
| 206 | |||
| 207 | // for getting out of messed up linking situations (i.e. caused by demo playback) |
||
| 208 | void obj_relink_all(); |
||
| 209 | |||
| 210 | // links an object into a segment's list of objects. |
||
| 211 | // takes object number and segment number |
||
| 212 | void obj_link(fvmobjptr &vmobjptr, vmobjptridx_t objnum, vmsegptridx_t segnum); |
||
| 213 | /* Link an object without checking whether the object is currently |
||
| 214 | * unlinked. This should be used only in cases where the caller is |
||
| 215 | * intentionally overriding the normal linking rules (such as loading |
||
| 216 | * objects from demos or from the network). |
||
| 217 | */ |
||
| 218 | void obj_link_unchecked(fvmobjptr &vmobjptr, vmobjptridx_t obj, vmsegptridx_t segnum); |
||
| 219 | |||
| 220 | // unlinks an object from a segment's list of objects |
||
| 221 | void obj_unlink(fvmobjptr &vmobjptr, fvmsegptr &vmsegptr, object_base &obj); |
||
| 222 | |||
| 223 | // initialize a new object. adds to the list for the given segment |
||
| 224 | // returns the object number |
||
| 225 | imobjptridx_t obj_create(object_type_t type, unsigned id, vmsegptridx_t segnum, const vms_vector &pos, const vms_matrix *orient, fix size, unsigned ctype, movement_type_t mtype, render_type_t rtype); |
||
| 226 | |||
| 227 | // make a copy of an object. returs num of new object |
||
| 228 | imobjptridx_t obj_create_copy(const object &srcobj, vmsegptridx_t newsegnum); |
||
| 229 | |||
| 230 | // remove object from the world |
||
| 231 | void obj_delete(d_level_unique_object_state &LevelUniqueObjectState, segment_array &Segments, vmobjptridx_t objnum); |
||
| 232 | |||
| 233 | // called after load. Takes number of objects, and objects should be |
||
| 234 | // compressed |
||
| 235 | void reset_objects(d_level_unique_object_state &, unsigned n_objs); |
||
| 236 | |||
| 237 | // make object array non-sparse |
||
| 238 | void compress_objects(); |
||
| 239 | |||
| 240 | // move all objects for the current frame |
||
| 241 | window_event_result game_move_all_objects(); // moves all objects |
||
| 242 | window_event_result endlevel_move_all_objects(); |
||
| 243 | |||
| 244 | // set viewer object to next object in array |
||
| 245 | void object_goto_next_viewer(); |
||
| 246 | |||
| 247 | // make object0 the player, setting all relevant fields |
||
| 248 | void init_player_object(); |
||
| 249 | |||
| 250 | // check if object is in object->segnum. if not, check the adjacent |
||
| 251 | // segs. if not any of these, returns false, else sets obj->segnum & |
||
| 252 | // returns true callers should really use find_vector_intersection() |
||
| 253 | // Note: this function is in gameseg.c |
||
| 254 | int update_object_seg(fvmobjptr &vmobjptr, const d_level_shared_segment_state &LevelSharedSegmentState, d_level_unique_segment_state &LevelUniqueSegmentState, vmobjptridx_t obj); |
||
| 255 | |||
| 256 | // Finds what segment *obj is in, returns segment number. If not in |
||
| 257 | // any segment, returns -1. Note: This function is defined in |
||
| 258 | // gameseg.h, but object.h depends on gameseg.h, and object.h is where |
||
| 259 | // object is defined...get it? |
||
| 260 | imsegptridx_t find_object_seg(const d_level_shared_segment_state &, d_level_unique_segment_state &, const object_base &obj); |
||
| 261 | |||
| 262 | // go through all objects and make sure they have the correct segment |
||
| 263 | // numbers used when debugging is on |
||
| 264 | void fix_object_segs(); |
||
| 265 | |||
| 266 | // Drops objects contained in objp. |
||
| 267 | imobjptridx_t object_create_robot_egg(object &objp); |
||
| 268 | imobjptridx_t object_create_robot_egg(int type, int id, int num, const vms_vector &init_vel, const vms_vector &pos, vmsegptridx_t segnum); |
||
| 269 | |||
| 270 | // Interface to object_create_egg, puts count objects of type type, id |
||
| 271 | // = id in objp and then drops them. |
||
| 272 | imobjptridx_t call_object_create_egg(const object_base &objp, unsigned count, int id); |
||
| 273 | |||
| 274 | void dead_player_end(); |
||
| 275 | |||
| 276 | // Extract information from an object (objp->orient, objp->pos, |
||
| 277 | // objp->segnum), stuff in a shortpos structure. See typedef |
||
| 278 | // shortpos. |
||
| 279 | void create_shortpos_little(const d_level_shared_segment_state &, shortpos &spp, const object_base &objp); |
||
| 280 | void create_shortpos_native(const d_level_shared_segment_state &, shortpos &spp, const object_base &objp); |
||
| 281 | |||
| 282 | // Extract information from a shortpos, stuff in objp->orient |
||
| 283 | // (matrix), objp->pos, objp->segnum |
||
| 284 | void extract_shortpos_little(vmobjptridx_t objp, const shortpos *spp); |
||
| 285 | |||
| 286 | // create and extract quaternion structure from object data which greatly saves bytes by using quaternion instead or orientation matrix |
||
| 287 | void create_quaternionpos(quaternionpos &qpp, const object_base &objp); |
||
| 288 | void extract_quaternionpos(vmobjptridx_t objp, quaternionpos &qpp); |
||
| 289 | |||
| 290 | // delete objects, such as weapons & explosions, that shouldn't stay |
||
| 291 | // between levels if clear_all is set, clear even proximity bombs |
||
| 292 | void clear_transient_objects(int clear_all); |
||
| 293 | |||
| 294 | // returns the number of a free object, updating Highest_object_index. |
||
| 295 | // Generally, obj_create() should be called to get an object, since it |
||
| 296 | // fills in important fields and does the linking. returns -1 if no |
||
| 297 | // free objects |
||
| 298 | imobjptridx_t obj_allocate(d_level_unique_object_state &); |
||
| 299 | |||
| 300 | // after calling init_object(), the network code has grabbed specific |
||
| 301 | // object slots without allocating them. Go though the objects & |
||
| 302 | // build the free list, then set the apporpriate globals Don't call |
||
| 303 | // this function if you don't know what you're doing. |
||
| 304 | void special_reset_objects(d_level_unique_object_state &); |
||
| 305 | |||
| 306 | // attaches an object, such as a fireball, to another object, such as |
||
| 307 | // a robot |
||
| 308 | void obj_attach(object_array &Objects, vmobjptridx_t parent, vmobjptridx_t sub); |
||
| 309 | |||
| 310 | void create_small_fireball_on_object(vmobjptridx_t objp, fix size_scale, int sound_flag); |
||
| 311 | window_event_result dead_player_frame(); |
||
| 312 | |||
| 313 | #if defined(DXX_BUILD_DESCENT_II) |
||
| 314 | extern int Drop_afterburner_blob_flag; //ugly hack |
||
| 315 | enum class game_marker_index : uint8_t; |
||
| 316 | enum class player_marker_index : uint8_t; |
||
| 317 | // returns object number |
||
| 318 | imobjptridx_t drop_marker_object(const vms_vector &pos, vmsegptridx_t segnum, const vms_matrix &orient, game_marker_index marker_num); |
||
| 319 | |||
| 320 | void wake_up_rendered_objects(const object &gmissp, window_rendered_data &window); |
||
| 321 | |||
| 322 | void fuelcen_check_for_goal(object &plrobj, const shared_segment &segp); |
||
| 323 | #endif |
||
| 324 | imobjptridx_t obj_find_first_of_type(fvmobjptridx &, object_type_t type); |
||
| 325 | |||
| 326 | void object_rw_swap(struct object_rw *obj_rw, int swap); |
||
| 327 | void reset_player_object(); |
||
| 328 | |||
| 329 | } |
||
| 330 | #endif |