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
33 changes: 25 additions & 8 deletions code/iff_defs/iff_defs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ int IFF_COLOR_TAGGED = 2;
// global only to file
SCP_vector <std::pair<color, color>> Iff_colors; // AL 1-2-97: Create two IFF colors, regular and bright

typedef struct {
int r;
int g;
int b;
} temp_color_t;

// parallel to Iff_colors
static SCP_vector<temp_color_t> temp_colors;

flag_def_list rti_flags[] = {
{ "crosshairs", RTIF_CROSSHAIRS, 0 },
{ "blink", RTIF_BLINK, 0 },
Expand Down Expand Up @@ -82,16 +91,8 @@ int iff_get_alpha_value(bool is_bright)
*/
int iff_init_color(int r, int g, int b)
{
typedef struct {
int r;
int g;
int b;
} temp_color_t;

int i, idx;

static SCP_vector<temp_color_t> temp_colors;

Assert(r >= 0 && r <= 255);
Assert(g >= 0 && g <= 255);
Assert(b >= 0 && b <= 255);
Expand Down Expand Up @@ -662,6 +663,22 @@ void iff_init()
resolve_iff_data();
}

void iff_close()
{
Iff_info.clear();
Iff_info_names.clear();
Iff_colors.clear();
temp_colors.clear();

attack_names.clear();
observed_color_table.clear();
accessibility_observed_color_table.clear();

strcpy_s(traitor_name, "Traitor");
Iff_traitor = 0;
AccessiblitySupported = false;
}

/**
* Find the iff name
*
Expand Down
3 changes: 3 additions & 0 deletions code/iff_defs/iff_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ extern int iff_init_color(int r, int g, int b);
// load the iff table
extern void iff_init();

// free the iff table
extern void iff_close();

// search for iff
extern int iff_lookup(const char *iff_name);

Expand Down
9 changes: 8 additions & 1 deletion test/src/iff_defs/test_iff_accessibility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ class IffAccessibilityTest : public test::FSTestFixture {
{
pushModDir("iff/tbm_adds_iff");
}

protected:
void TearDown() override
{
iff_close();

test::FSTestFixture::TearDown();
}
};

namespace {
Expand All @@ -31,7 +39,6 @@ ::testing::AssertionResult has_rgb(int color_index, int r, int g, int b)
}
} // namespace

// one test: nothing clears Iff_info, so a second iff_init() in the process fails on duplicate IFF names
TEST_F(IffAccessibilityTest, TbmIffsKeepTheirColorsAndBuiltInsUseAccessibilityColors)
{
iff_init();
Expand Down
Loading