Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions code/ai/aicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13705,7 +13705,7 @@ int ai_acquire_emerge_path(object *pl_objp, int parent_objnum, int allowed_path_
ship_info* parent_sip = &Ship_info[parent_shipp->ship_info_index];

polymodel *pm = model_get( parent_sip->model_num );
ship_bay *bay = pm->ship_bay;
const auto& bay = pm->ship_bay;

if ( bay == nullptr ) {
Warning(LOCATION, "Ship %s was set to arrive from fighter bay on object %s, but no fighter bay exists on that ships' model (%s).\n", shipp->ship_name, parent_shipp->ship_name, pm->filename);
Expand Down Expand Up @@ -13920,9 +13920,8 @@ int ai_find_closest_depart_path(ai_info *aip, polymodel *pm, int allowed_path_ma
float dist, min_dist, min_free_dist;
vec3d *source;
model_path *mp;
ship_bay *bay;

bay = pm->ship_bay;
const auto& bay = pm->ship_bay;

best_free_path = best_path = -1;
min_free_dist = min_dist = 1e20f;
Expand Down Expand Up @@ -13999,9 +13998,9 @@ int ai_acquire_depart_path(object *pl_objp, int parent_objnum, int allowed_path_

object *parent_objp = &Objects[parent_objnum];
polymodel *pm = model_get(Ship_info[Ships[parent_objp->instance].ship_info_index].model_num );
ship_bay *bay = pm->ship_bay;
const auto& bay = pm->ship_bay;

if ( bay == NULL )
if ( bay == nullptr )
return -1;
if ( bay->num_paths <= 0 )
return -1;
Expand Down Expand Up @@ -14092,11 +14091,10 @@ void ai_bay_depart()

// Volition bay code
polymodel *pm;
ship_bay *bay;

pm = model_get(Ship_info[Ships[Objects[aip->goal_objnum].instance].ship_info_index].model_num);
bay = pm->ship_bay;
if ( bay != NULL ) {
const auto& bay = pm->ship_bay;
if ( bay != nullptr ) {
bay->depart_flags &= ~(1<<aip->submode_parm0);
}

Expand Down
24 changes: 24 additions & 0 deletions code/globalincs/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ struct is_dereferenceable_pointer<T, typename std::enable_if_t<std::is_pointer_v
template<typename T>
inline constexpr bool is_dereferenceable_pointer_v = is_dereferenceable_pointer<T>::value;

template<typename T, typename Enable = void>
struct is_smart_pointer : std::false_type {};

template<typename T>
struct is_smart_pointer<T, std::enable_if_t<std::is_same_v<std::remove_cv_t<T>, std::shared_ptr<typename T::element_type>>>> : std::true_type {};

template<typename T>
struct is_smart_pointer<T, std::enable_if_t<std::is_same_v<std::remove_cv_t<T>, std::shared_ptr<typename T::element_type[]>>>> : std::true_type {};

template<typename T>
struct is_smart_pointer<T, std::enable_if_t<std::is_same_v<std::remove_cv_t<T>, std::unique_ptr<typename T::element_type>>>> : std::true_type {};

template<typename T>
struct is_smart_pointer<T, std::enable_if_t<std::is_same_v<std::remove_cv_t<T>, std::unique_ptr<typename T::element_type[]>>>> : std::true_type {};

template<typename T>
struct is_smart_pointer<T, std::enable_if_t<std::is_same_v<std::remove_cv_t<T>, std::weak_ptr<typename T::element_type>>>> : std::true_type {};

template<typename T>
struct is_smart_pointer<T, std::enable_if_t<std::is_same_v<std::remove_cv_t<T>, std::weak_ptr<typename T::element_type[]>>>> : std::true_type {};

template<typename T>
inline constexpr bool is_smart_pointer_v = is_smart_pointer<T>::value;

template<class T, template<class...> class U>
inline constexpr bool is_instance_of_v = std::false_type{};

Expand Down
5 changes: 2 additions & 3 deletions code/graphics/2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,8 @@ class vertex_buffer
};

struct indexed_vertex_source {
void* Vertex_list = nullptr;
void* Index_list = nullptr;

std::shared_ptr<uint8_t[]> Vertex_list = nullptr;
std::shared_ptr<uint8_t[]> Index_list = nullptr;
gr_buffer_handle Vbuffer_handle;
size_t Vertex_offset = 0;
size_t Base_vertex_offset = 0;
Expand Down
46 changes: 23 additions & 23 deletions code/model/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ class bsp_info
matrix frame_of_reference; // used to be called 'orientation' - this is just used for setting the rotation axis and the animation angles

int bsp_data_size;
ubyte *bsp_data;
std::shared_ptr<ubyte[]> bsp_data;

int collision_tree_index;

Expand Down Expand Up @@ -485,7 +485,7 @@ class bsp_info
vertex_buffer buffer;
vertex_buffer trans_buffer;

vertex *outline_buffer;
std::shared_ptr<vertex[]> outline_buffer;
uint n_verts_outline;

vec3d render_box_min;
Expand All @@ -508,7 +508,7 @@ class bsp_info
typedef struct mp_vert {
vec3d pos; // xyz coordinates of vertex in object's frame of reference
int nturrets; // number of turrets guarding this vertex
int *turret_ids; // array of indices into ship_subsys linked list (can't index using [] though)
std::shared_ptr<int[]> turret_ids; // array of indices into ship_subsys linked list (can't index using [] though)
float radius; // How far the closest obstruction is from this vertex
} mp_vert;

Expand All @@ -517,7 +517,7 @@ typedef struct model_path {
char parent_name[MAX_NAME_LEN]; // parent name of submodel that path is linked to in POF
int parent_submodel;
int nverts;
mp_vert *verts;
std::shared_ptr<mp_vert[]> verts;
int goal; // Which of the verts is the one closest to the goal of this path
int type; // What this path takes you to... See MP_TYPE_??? defines above for details
int value; // This depends on the type.
Expand Down Expand Up @@ -567,7 +567,7 @@ struct glow_point{

typedef struct thruster_bank {
int num_points;
glow_point *points;
std::shared_ptr<glow_point[]> points;

// Engine wash info
struct engine_wash_info *wash_info_pointer; // index into Engine_wash_info
Expand All @@ -590,7 +590,7 @@ typedef struct glow_point_bank { // glow bank structure -Bobboau
int submodel_parent;
int LOD;
int num_points;
glow_point *points;
std::shared_ptr<glow_point[]> points;
int glow_bitmap;
int glow_neb_bitmap;
} glow_point_bank;
Expand Down Expand Up @@ -650,7 +650,7 @@ typedef struct dock_bay {
int num_slots;
int type_flags; // indicates what this docking bay can be used for (i.e. cargo/rearm, etc)
int num_spline_paths; // number of spline paths which lead to this docking bay
int *splines; // array of indices into the Spline_path array
std::shared_ptr<int[]> splines; // array of indices into the Spline_path array
int parent_submodel; // if this dockpoint should be relative to a submodel instead of the main model
char name[MAX_NAME_LEN]; // name of this docking location
vec3d pnt[MAX_DOCK_SLOTS];
Expand Down Expand Up @@ -692,14 +692,14 @@ typedef struct shield_vertex {
struct shield_info {
int nverts;
int ntris;
shield_vertex *verts;
shield_tri *tris;
std::shared_ptr<shield_vertex[]> verts;
std::shared_ptr<shield_tri[]> tris;

gr_buffer_handle buffer_id;
std::shared_ptr<gr_buffer_handle> buffer_id;
int buffer_n_verts;
vertex_layout layout;

shield_info() : nverts(0), ntris(0), verts(NULL), tris(NULL), buffer_id(-1), buffer_n_verts(0), layout() { }
shield_info() : nverts(0), ntris(0), verts(nullptr), tris(nullptr), buffer_id(std::make_shared<gr_buffer_handle>(gr_buffer_handle::invalid())), buffer_n_verts(0) { }
};

#define BSP_LIGHT_TYPE_WEAPON 1
Expand Down Expand Up @@ -852,7 +852,7 @@ class polymodel
vec3d bounding_box[8];

int num_lights; // how many lights there are
bsp_light * lights; // array of light info
std::shared_ptr<bsp_light[]> lights; // array of light info

int n_view_positions; // number of viewing positions available on this ship
eye view_positions[MAX_EYES]; //viewing positions. Default to {0,0,0}. in location 0
Expand All @@ -866,35 +866,35 @@ class polymodel
int n_textures;
texture_map maps[MAX_MODEL_TEXTURES];

bsp_info *submodel; // an array of size n_models of submodel info.
std::shared_ptr<bsp_info[]> submodel; // an array of size n_models of submodel info.

// linked lists for special polygon types on this model. Most ships I think will have most
// of these. (most ships however, probably won't have approach points).
int n_guns; // number of primary weapon banks (not counting turrets)
int n_missiles; // number of secondary weapon banks (not counting turrets)
int n_docks; // number of docking points
int n_thrusters; // number of thrusters on this ship.
w_bank *gun_banks; // array of gun banks
w_bank *missile_banks; // array of missile banks
dock_bay *docking_bays; // array of docking point pairs
thruster_bank *thrusters; // array of thruster objects -- likely to change in the future
ship_bay_t *ship_bay; // contains path indexes for ship bay approach/depart paths
std::shared_ptr<w_bank[]> gun_banks; // array of gun banks
std::shared_ptr<w_bank[]> missile_banks; // array of missile banks
std::shared_ptr<dock_bay[]> docking_bays; // array of docking point pairs
std::shared_ptr<thruster_bank[]> thrusters; // array of thruster objects -- likely to change in the future
std::shared_ptr<ship_bay_t> ship_bay; // contains path indexes for ship bay approach/depart paths

shield_info shield; // new shield information
ubyte *shield_collision_tree;
std::shared_ptr<ubyte[]> shield_collision_tree;
int sldc_size;
SCP_vector<vec3d> shield_points;

int n_paths;
model_path *paths;
std::shared_ptr<model_path[]> paths;

// physics info
float mass;
vec3d center_of_mass;
matrix moment_of_inertia;

int num_xc; // number of cross sections
cross_section* xc; // pointer to array of cross sections (used in big ship explosions)
std::shared_ptr<cross_section[]> xc; // pointer to array of cross sections (used in big ship explosions)

int num_split_plane; // number of split planes
float split_plane[MAX_SPLIT_PLANE]; // actual split plane z coords (for big ship explosions)
Expand All @@ -905,13 +905,13 @@ class polymodel
#ifndef NDEBUG
int ram_used; // How much RAM this model uses
int debug_info_size;
char *debug_info;
std::shared_ptr<char[]> debug_info;
#endif

int used_this_mission; // used for page-in system, how many times this model has been loaded per mission - taylor

int n_glow_point_banks; // number of glow points on this ship. -Bobboau
glow_point_bank *glow_point_banks; // array of glow objects -Bobboau
std::shared_ptr<glow_point_bank[]> glow_point_banks; // array of glow objects -Bobboau

indexed_vertex_source vert_source;

Expand Down
18 changes: 9 additions & 9 deletions code/model/modelcollide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ bool mc_shield_check_common(shield_tri *tri)
// also finds the uv's where the ray hit.
if ( fvi_point_face(&hitpoint, 3, points, &tri->norm, NULL,NULL,NULL ) ) {
Mc->hit_dist = dist;
Mc->shield_hit_tri = (int)(tri - Mc_pm->shield.tris);
Mc->shield_hit_tri = (int)(tri - Mc_pm->shield.tris.get());
Mc->hit_point = hitpoint;
Mc->hit_normal = tri->norm;
Mc->hit_submodel = -1;
Expand All @@ -877,7 +877,7 @@ bool mc_shield_check_common(shield_tri *tri)
// same behavior whether face or edge
// normal, edge_hit, hit_point all updated thru sphereline_face
sphere_check_closest_shield_dist = Mc->hit_dist;
Mc->shield_hit_tri = (int)(tri - Mc_pm->shield.tris);
Mc->shield_hit_tri = (int)(tri - Mc_pm->shield.tris.get());
Mc->hit_submodel = -1;
Mc->num_hits++;
return true; // We hit, so we're done
Expand All @@ -893,22 +893,22 @@ bool mc_check_sldc(int offset)
if (offset > Mc_pm->sldc_size - 5) //no way is this big enough
return false;

int* type_p = (int*)(Mc_pm->shield_collision_tree + offset);
int* type_p = (int*)(Mc_pm->shield_collision_tree.get() + offset);

// not used
//int *size_p = (int *)(Mc_pm->shield_collision_tree+offset+4);
// split and polygons
auto* minbox_p = (vec3d*)(Mc_pm->shield_collision_tree + offset + 8);
auto* maxbox_p = (vec3d*)(Mc_pm->shield_collision_tree + offset + 20);
auto* minbox_p = (vec3d*)(Mc_pm->shield_collision_tree.get() + offset + 8);
auto* maxbox_p = (vec3d*)(Mc_pm->shield_collision_tree.get() + offset + 20);

// split
auto* front_offset_p = (unsigned int*)(Mc_pm->shield_collision_tree + offset + 32);
auto* back_offset_p = (unsigned int*)(Mc_pm->shield_collision_tree + offset + 36);
auto* front_offset_p = (unsigned int*)(Mc_pm->shield_collision_tree.get() + offset + 32);
auto* back_offset_p = (unsigned int*)(Mc_pm->shield_collision_tree.get() + offset + 36);

// polygons
auto* num_polygons_p = (unsigned int*)(Mc_pm->shield_collision_tree + offset + 32);
auto* num_polygons_p = (unsigned int*)(Mc_pm->shield_collision_tree.get() + offset + 32);

auto* shld_polys = (unsigned int*)(Mc_pm->shield_collision_tree + offset + 36);
auto* shld_polys = (unsigned int*)(Mc_pm->shield_collision_tree.get() + offset + 36);



Expand Down
Loading
Loading