Skip to content

Commit 76b9868

Browse files
committed
Merge pull request #512 from Goober5000/dumb_rotation_refactor
Dumb rotation refactor
2 parents 8dc4030 + 59d6a44 commit 76b9868

File tree

14 files changed

+291
-184
lines changed

14 files changed

+291
-184
lines changed

code/asteroid/asteroid.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,11 @@ object *asteroid_create(asteroid_field *asfieldp, int asteroid_type, int asteroi
329329
}
330330

331331
asp->objnum = objnum;
332+
asp->model_instance_num = -1;
333+
334+
if (model_get(asip->model_num[asteroid_subtype])->flags & PM_FLAG_HAS_DUMB_ROTATE) {
335+
asp->model_instance_num = model_create_instance(false, asip->model_num[asteroid_subtype]);
336+
}
332337

333338
// Add to Asteroid_used_list
334339
asteroid_obj_list_add(objnum);
@@ -828,10 +833,12 @@ void asteroid_delete( object * obj )
828833

829834
asp = &Asteroids[num];
830835

831-
Assert( Num_asteroids >= 0 );
836+
if (asp->model_instance_num >= 0)
837+
model_delete_instance(asp->model_instance_num);
832838

833839
asp->flags = 0;
834840
Num_asteroids--;
841+
Assert(Num_asteroids >= 0);
835842

836843
asteroid_obj_list_remove( obj );
837844
}
@@ -930,7 +937,7 @@ int asteroid_check_collision(object *pasteroid, object *other_obj, vec3d *hitpos
930937
if ( asteroid_hit_info == NULL ) {
931938
// asteroid weapon collision
932939
Assert( other_obj->type == OBJ_WEAPON );
933-
mc.model_instance_num = -1;
940+
mc.model_instance_num = Asteroids[num].model_instance_num;
934941
mc.model_num = Asteroid_info[Asteroids[num].asteroid_type].model_num[asteroid_subtype]; // Fill in the model to check
935942
model_clear_instance( mc.model_num );
936943
mc.orient = &pasteroid->orient; // The object's orient
@@ -1107,7 +1114,7 @@ int asteroid_check_collision(object *pasteroid, object *other_obj, vec3d *hitpos
11071114

11081115
} else {
11091116
// Asteroid is heavier obj
1110-
mc.model_instance_num = -1;
1117+
mc.model_instance_num = Asteroids[num].model_instance_num;
11111118
mc.model_num = Asteroid_info[Asteroids[num].asteroid_type].model_num[asteroid_subtype]; // Fill in the model to check
11121119
model_clear_instance( mc.model_num );
11131120
mc.orient = &pasteroid->orient; // The object's orient

code/asteroid/asteroid.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class asteroid_info
9898
typedef struct asteroid {
9999
int flags;
100100
int objnum;
101+
int model_instance_num;
101102
int asteroid_type; // 0..MAX_DEBRIS_TYPES
102103
int asteroid_subtype; // Index in asteroid_info for modelnum and modelp
103104
int check_for_wrap; // timestamp to check for asteroid wrapping around field

code/fred2/management.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ int query_ship_name_duplicate(int ship);
135135
char *reg_read_string( char *section, char *name, char *default_value );
136136

137137
extern int Nmodel_num;
138+
extern int Nmodel_instance_num;
138139
extern matrix Nmodel_orient;
139140
extern int Nmodel_bitmap;
140141

@@ -955,6 +956,7 @@ void clear_mission()
955956

956957
Nmodel_flags = DEFAULT_NMODEL_FLAGS;
957958
Nmodel_num = -1;
959+
Nmodel_instance_num = -1;
958960
vm_set_identity(&Nmodel_orient);
959961
Nmodel_bitmap = -1;
960962

code/model/model.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ extern int model_render_flags_size;
3535
#define MOVEMENT_TYPE_ROT_SPECIAL 2 // for turrets only
3636
#define MOVEMENT_TYPE_TRIGGERED 3 //triggered rotation
3737
#define MOVEMENT_TYPE_LOOK_AT 4 // the subobject is always looking at a 'look at' subobject, as best it can - Bobboau
38+
#define MOVEMENT_TYPE_DUMB_ROTATE 5
3839

3940

4041
// DA 11/13/98 Reordered to account for difference between max and game
@@ -121,19 +122,18 @@ typedef struct polymodel_instance {
121122
#define MSS_FLAG_NO_SS_TARGETING (1 << 16) // toggles the subsystem targeting for the turret
122123
#define MSS_FLAG_TURRET_RESET_IDLE (1 << 17) // makes turret reset to their initial position if the target is out of field of view
123124
#define MSS_FLAG_TURRET_ALT_MATH (1 << 18) // tells the game to use additional calculations should turret have a defined y fov
124-
#define MSS_FLAG_DUM_ROTATES (1 << 19) // Bobboau
125-
#define MSS_FLAG_CARRY_SHOCKWAVE (1 << 20) // subsystem - even with 'carry no damage' flag - will carry shockwave damage to the hull
126-
#define MSS_FLAG_ALLOW_LANDING (1 << 21) // This subsystem can be landed on
127-
#define MSS_FLAG_FOV_EDGE_CHECK (1 << 22) // Tells the game to use better FOV edge checking with this turret
128-
#define MSS_FLAG_FOV_REQUIRED (1 << 23) // Tells game not to allow this turret to attempt targeting objects out of FOV
129-
#define MSS_FLAG_NO_REPLACE (1 << 24) // set the subsys not to draw replacement ('destroyed') model
130-
#define MSS_FLAG_NO_LIVE_DEBRIS (1 << 25) // sets the subsys not to release live debris
131-
#define MSS_FLAG_IGNORE_IF_DEAD (1 << 26) // tells homing missiles to ignore the subsys if its dead and home on to hull instead of earlier subsys pos
132-
#define MSS_FLAG_ALLOW_VANISHING (1 << 27) // allows subsystem to vanish (prevents explosions & sounds effects from being played)
133-
#define MSS_FLAG_DAMAGE_AS_HULL (1 << 28) // applies armor damage to subsystem instead of subsystem damage - FUBAR
134-
#define MSS_FLAG_TURRET_LOCKED (1 << 29) // Turret starts locked by default - Sushi
135-
#define MSS_FLAG_NO_AGGREGATE (1 << 30) // Don't include with aggregate subsystem types - Goober5000
136-
#define MSS_FLAG_TURRET_ANIM_WAIT (1 << 31) // Turret won't fire until animation is complete - Sushi
125+
#define MSS_FLAG_CARRY_SHOCKWAVE (1 << 19) // subsystem - even with 'carry no damage' flag - will carry shockwave damage to the hull
126+
#define MSS_FLAG_ALLOW_LANDING (1 << 20) // This subsystem can be landed on
127+
#define MSS_FLAG_FOV_EDGE_CHECK (1 << 21) // Tells the game to use better FOV edge checking with this turret
128+
#define MSS_FLAG_FOV_REQUIRED (1 << 22) // Tells game not to allow this turret to attempt targeting objects out of FOV
129+
#define MSS_FLAG_NO_REPLACE (1 << 23) // set the subsys not to draw replacement ('destroyed') model
130+
#define MSS_FLAG_NO_LIVE_DEBRIS (1 << 24) // sets the subsys not to release live debris
131+
#define MSS_FLAG_IGNORE_IF_DEAD (1 << 25) // tells homing missiles to ignore the subsys if its dead and home on to hull instead of earlier subsys pos
132+
#define MSS_FLAG_ALLOW_VANISHING (1 << 26) // allows subsystem to vanish (prevents explosions & sounds effects from being played)
133+
#define MSS_FLAG_DAMAGE_AS_HULL (1 << 27) // applies armor damage to subsystem instead of subsystem damage - FUBAR
134+
#define MSS_FLAG_TURRET_LOCKED (1 << 28) // Turret starts locked by default - Sushi
135+
#define MSS_FLAG_NO_AGGREGATE (1 << 29) // Don't include with aggregate subsystem types - Goober5000
136+
#define MSS_FLAG_TURRET_ANIM_WAIT (1 << 30) // Turret won't fire until animation is complete - Sushi
137137

138138
#define MSS_FLAG2_PLAYER_TURRET_SOUND (1 << 0)
139139
#define MSS_FLAG2_TURRET_ONLY_TARGET_IF_CAN_FIRE (1 << 1) // Turrets only target things they're allowed to shoot at (e.g. if check-hull fails, won't keep targeting)
@@ -300,7 +300,7 @@ class bsp_info
300300
public:
301301
bsp_info()
302302
: movement_type(-1), movement_axis(0), can_move(false), bsp_data_size(0), bsp_data(NULL), collision_tree_index(-1),
303-
rad(0.0f), blown_off(0), my_replacement(-1), i_replace(-1), is_live_debris(0), num_live_debris(0), sii(NULL),
303+
rad(0.0f), blown_off(0), my_replacement(-1), i_replace(-1), is_live_debris(0), num_live_debris(0),
304304
is_thruster(0), is_damaged(0), parent(-1), num_children(0), first_child(-1), next_sibling(-1), num_details(0),
305305
num_arcs(0), outline_buffer(NULL), n_verts_outline(0), render_sphere_radius(0.0f), use_render_box(0), use_render_box_offset(false),
306306
use_render_sphere(0), use_render_sphere_offset(false), gun_rotation(false), no_collisions(false),
@@ -352,8 +352,6 @@ class bsp_info
352352
int num_live_debris; // num live debris models assocaiated with a submodel
353353
int live_debris[MAX_LIVE_DEBRIS]; // array of live debris submodels for a submodel
354354

355-
submodel_instance_info *sii; // stuff needed for collision from rotations
356-
357355
int is_thruster;
358356
int is_damaged;
359357

@@ -623,6 +621,7 @@ typedef struct insignia {
623621
#define PM_FLAG_AUTOCEN (1<<1) // contains autocentering info
624622
#define PM_FLAG_TRANS_BUFFER (1<<2) // render transparency buffer
625623
#define PM_FLAG_BATCHED (1<<3) // this model can be batch rendered
624+
#define PM_FLAG_HAS_DUMB_ROTATE (1<<4) // whether this model has a dumb-rotate submodel somewhere
626625

627626
// Goober5000
628627
class texture_info
@@ -831,7 +830,7 @@ void model_instance_free_all();
831830
// Loads a model from disk and returns the model number it loaded into.
832831
int model_load(char *filename, int n_subsystems, model_subsystem *subsystems, int ferror = 1, int duplicate = 0);
833832

834-
int model_create_instance(int model_num);
833+
int model_create_instance(bool is_ship, int model_num);
835834
void model_delete_instance(int model_instance_num);
836835

837836
// Goober5000
@@ -998,7 +997,8 @@ extern void model_make_turret_matrix(int model_num, model_subsystem * turret );
998997

999998
// Rotates the angle of a submodel. Use this so the right unlocked axis
1000999
// gets stuffed.
1001-
extern void submodel_rotate(model_subsystem *psub, submodel_instance_info * sii);
1000+
extern void submodel_rotate(model_subsystem *psub, submodel_instance_info *sii);
1001+
extern void submodel_rotate(bsp_info *sm, submodel_instance_info *sii);
10021002

10031003
// Rotates the angle of a submodel. Use this so the right unlocked axis
10041004
// gets stuffed. Does this for stepped rotations
@@ -1054,8 +1054,8 @@ void model_set_instance_info(submodel_instance_info *sii, float turn_rate, float
10541054
extern void model_clear_instance_info(submodel_instance_info * sii);
10551055

10561056
// Sets the submodel instance data in a submodel
1057-
extern void model_set_instance(int model_num, int sub_model_num, submodel_instance_info * sii, int flags = 0 );
1058-
extern void model_set_instance_techroom(int model_num, int sub_model_num, float angle_1, float angle_2 );
1057+
extern void model_set_instance(int model_num, int sub_model_num, submodel_instance_info *sii, int flags = 0);
1058+
extern void model_set_instance_techroom(int model_num, int sub_model_num, float angle_1, float angle_2);
10591059

10601060
void model_update_instance(int model_instance_num, int sub_model_num, submodel_instance_info *sii, int flags);
10611061
void model_instance_dumb_rotation(int model_instance_num);
@@ -1370,7 +1370,7 @@ void model_finish_cloak(int full_cloak);
13701370

13711371
void model_do_look_at(int model_num); //Bobboau
13721372

1373-
void model_do_dumb_rotation(int modelnum); //Bobboau
1373+
void model_do_dumb_rotations(int model_instance_num = -1);
13741374

13751375
int model_should_render_engine_glow(int objnum, int bank_obj);
13761376

code/model/modelinterp.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,8 +2011,6 @@ void model_render_DEPRECATED(int model_num, matrix *orient, vec3d * pos, uint fl
20112011

20122012
polymodel *pm = model_get(model_num);
20132013

2014-
model_do_dumb_rotation(model_num);
2015-
20162014
if (flags & MR_FORCE_CLAMP)
20172015
gr_set_texture_addressing(TMAP_ADDRESS_CLAMP);
20182016

0 commit comments

Comments
 (0)