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
48 changes: 40 additions & 8 deletions code/mission/missionmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#include "species_defs/species_defs.h"
#include "utils/Random.h"

#include <utility> // for std::exchange

bool Allow_generic_backup_messages = false;
bool Always_loop_head_anis = false;
bool Use_newer_head_ani_suffix = false;
Expand Down Expand Up @@ -72,14 +74,44 @@ builtin_message::builtin_message(const builtin_message& other)

builtin_message& builtin_message::operator=(const builtin_message& other)
{
name = other.used_strdup ? vm_strdup(other.name) : other.name;
occurrence_chance = other.occurrence_chance;
max_count = other.max_count;
min_delay = other.min_delay;
priority = other.priority;
timing = other.timing;
fallback = other.fallback;
used_strdup = other.used_strdup;
if (this != &other)
{
const char* new_name = other.used_strdup ? vm_strdup(other.name) : other.name;
if (used_strdup)
vm_free(const_cast<char*>(name));

name = new_name;
occurrence_chance = other.occurrence_chance;
max_count = other.max_count;
min_delay = other.min_delay;
priority = other.priority;
timing = other.timing;
fallback = other.fallback;
used_strdup = other.used_strdup;
}
return *this;
}

builtin_message::builtin_message(builtin_message&& other) noexcept
: name(std::exchange(other.name, nullptr)), occurrence_chance(other.occurrence_chance), max_count(other.max_count), min_delay(other.min_delay), priority(other.priority), timing(other.timing), fallback(other.fallback), used_strdup(std::exchange(other.used_strdup, false))
{}

builtin_message& builtin_message::operator=(builtin_message&& other) noexcept
{
if (this != &other)
{
if (used_strdup)
vm_free(const_cast<char*>(name));

name = std::exchange(other.name, nullptr);
occurrence_chance = other.occurrence_chance;
max_count = other.max_count;
min_delay = other.min_delay;
priority = other.priority;
timing = other.timing;
fallback = other.fallback;
used_strdup = std::exchange(other.used_strdup, false);
}
return *this;
}

Expand Down
7 changes: 4 additions & 3 deletions code/mission/missionmessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ typedef struct builtin_message {
bool used_strdup;

builtin_message(const char* _name, int _occurrence_chance, int _max_count, int _min_delay, int _priority, int _timing, int _fallback, bool _used_strdup);
// since we need a destructor, we need the other four special member functions as well
// since we need a destructor, we need the other four special member functions as well;
// all four must handle the conditionally-owned name so they can't be defaulted
~builtin_message();
builtin_message(const builtin_message& other);
builtin_message& operator=(const builtin_message& other);
builtin_message(builtin_message&& other) noexcept = default;
builtin_message& operator=(builtin_message&& other) noexcept = default;
builtin_message(builtin_message&& other) noexcept;
builtin_message& operator=(builtin_message&& other) noexcept;
} builtin_message;

// If these are changed or updated be sure to update the map in scripting/api/libs/mission.cpp and the connected lua enumerations!
Expand Down
7 changes: 6 additions & 1 deletion code/model/modelread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3245,7 +3245,7 @@ int model_load(const char* filename, ship_info* sip, ErrorType error_type, bool

if (sip != nullptr) {
n_subsystems = sip->n_subsystems;
subsystems = sip->subsystems;
subsystems = sip->subsystems.get();
}

num = -1;
Expand Down Expand Up @@ -6025,6 +6025,11 @@ void parse_glowpoint_table(const char *filename)

void glowpoint_init()
{
// ship_info and prop_info store indices into glowpoint_bank_overrides
extern bool Ships_inited;
extern bool Props_inited;
Assertion(!Ships_inited && !Props_inited, "glowpoint_init() must be called before ship_init() and prop_init()");

glowpoint_bank_overrides.clear();
parse_glowpoint_table("glowpoints.tbl");
parse_modular_table(NOX("*-gpo.tbm"), parse_glowpoint_table);
Expand Down
20 changes: 9 additions & 11 deletions code/model/modelrender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1946,7 +1946,6 @@ void model_render_set_glow_points(const polymodel *pm, int objnum)
int time = timestamp();
glow_point_bank_override *gpo = nullptr;
bool override_all = false;
SCP_unordered_map<int, void*>::iterator gpoi;
ship_info *sip = nullptr;
ship *shipp = nullptr;

Expand All @@ -1960,11 +1959,11 @@ void model_render_set_glow_points(const polymodel *pm, int objnum)
if ( objp != NULL && objp->type == OBJ_SHIP ) {
shipp = &Ships[Objects[objnum].instance];
sip = &Ship_info[shipp->ship_info_index];
gpoi = sip->glowpoint_bank_override_map.find(-1);
auto gpoi = sip->glowpoint_bank_override_map.find(-1);

if (gpoi != sip->glowpoint_bank_override_map.end()) {
override_all = true;
gpo = (glow_point_bank_override*)sip->glowpoint_bank_override_map[-1];
gpo = &glowpoint_bank_overrides[gpoi->second];
}
}
}
Expand All @@ -1973,12 +1972,12 @@ void model_render_set_glow_points(const polymodel *pm, int objnum)
glow_point_bank *bank = &pm->glow_point_banks[i];

if ( !override_all && sip ) {
gpoi = sip->glowpoint_bank_override_map.find(i);
auto gpoi = sip->glowpoint_bank_override_map.find(i);

if ( gpoi != sip->glowpoint_bank_override_map.end() ) {
gpo = (glow_point_bank_override*) sip->glowpoint_bank_override_map[i];
gpo = &glowpoint_bank_overrides[gpoi->second];
} else {
gpo = NULL;
gpo = nullptr;
}
}

Expand Down Expand Up @@ -2013,26 +2012,25 @@ void model_render_glow_points(const polymodel *pm, const polymodel_instance *pmi

glow_point_bank_override *gpo = nullptr;
bool override_all = false;
SCP_unordered_map<int, void*>::iterator gpoi;
ship_info *sip = nullptr;

if ( shipp ) {
sip = &Ship_info[shipp->ship_info_index];
gpoi = sip->glowpoint_bank_override_map.find(-1);
auto gpoi = sip->glowpoint_bank_override_map.find(-1);

if(gpoi != sip->glowpoint_bank_override_map.end()) {
override_all = true;
gpo = (glow_point_bank_override*) sip->glowpoint_bank_override_map[-1];
gpo = &glowpoint_bank_overrides[gpoi->second];
}
}

for (i = 0; i < pm->n_glow_point_banks; i++ ) {
glow_point_bank *bank = &pm->glow_point_banks[i];

if(!override_all && sip) {
gpoi = sip->glowpoint_bank_override_map.find(i);
auto gpoi = sip->glowpoint_bank_override_map.find(i);
if(gpoi != sip->glowpoint_bank_override_map.end()) {
gpo = (glow_point_bank_override*) sip->glowpoint_bank_override_map[i];
gpo = &glowpoint_bank_overrides[gpoi->second];
} else {
gpo = nullptr;
}
Expand Down
4 changes: 2 additions & 2 deletions code/prop/prop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ int prop_create(const matrix* orient, const vec3d* pos, int prop_type, const cha

auto gpoi = pip->glowpoint_bank_override_map.find(bank);
if (gpoi != pip->glowpoint_bank_override_map.end()) {
gpo = (glow_point_bank_override*)pip->glowpoint_bank_override_map[bank];
gpo = &glowpoint_bank_overrides[gpoi->second];
}

if (gpo) {
Expand Down Expand Up @@ -637,7 +637,7 @@ static void prop_model_change(int n, int prop_type)

auto gpoi = sip->glowpoint_bank_override_map.find(bank);
if (gpoi != sip->glowpoint_bank_override_map.end()) {
gpo = (glow_point_bank_override*)sip->glowpoint_bank_override_map[bank];
gpo = &glowpoint_bank_overrides[gpoi->second];
}

if (gpo) {
Expand Down
2 changes: 1 addition & 1 deletion code/prop/prop.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ typedef struct prop_info {
int model_num = -1; // The model number of the loaded POF
int num_detail_levels; // Detail levels of the model
int detail_distance[MAX_PROP_DETAIL_LEVELS]; // distance to change detail levels at
SCP_unordered_map<int, void*> glowpoint_bank_override_map; // Glow point bank overrides currently unused
SCP_unordered_map<int, int> glowpoint_bank_override_map; // Glow point bank overrides currently unused; values index glowpoint_bank_overrides
flagset<Prop::Info_Flags> flags; // Info flags
SCP_map<SCP_string, SCP_string> custom_data; // Custom data for this prop
SCP_vector<custom_string> custom_strings; // Custom strings for this prop
Expand Down
Loading
Loading