Skip to content
Merged
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: 31 additions & 17 deletions code/localization/localize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ typedef struct {
SCP_unordered_map<int, lcl_xstr> Xstr_table_map;
bool Xstr_inited = false;

// Distinct from Xstr_inited. FRED and qtfred set Xstr_inited without parsing so that XSTR works without actually localizing anything.
static bool Xstr_tables_parsed = false;


// table/mission externalization stuff --------------------
#define PARSE_TEXT_BUF_SIZE PARSE_BUF_SIZE
Expand Down Expand Up @@ -190,26 +193,28 @@ void lcl_init(int lang_init)
// initialize encryption
encrypt_init();

// set up the first language (which should be English)
Lcl_languages.push_back(Lcl_builtin_languages[0]);
if (Lcl_languages.empty()) {
// set up the first language (which should be English)
Lcl_languages.push_back(Lcl_builtin_languages[0]);

// check string.tbl to see which languages we support
try
{
parse_stringstbl_quick("strings.tbl");
}
catch (const parse::ParseException& e)
{
mprintf(("TABLES: Unable to parse '%s'! Error message = %s.\n", "strings.tbl", e.what()));
}
// check string.tbl to see which languages we support
try
{
parse_stringstbl_quick("strings.tbl");
}
catch (const parse::ParseException& e)
{
mprintf(("TABLES: Unable to parse '%s'! Error message = %s.\n", "strings.tbl", e.what()));
}

parse_modular_table(NOX("*-lcl.tbm"), parse_stringstbl_quick);
parse_modular_table(NOX("*-lcl.tbm"), parse_stringstbl_quick);

// if we only have one language at this point, we need to setup the builtin languages as we might be dealing with an old style strings.tbl
// which doesn't support anything beyond the builtin languages. Note, we start at i = 1 because we added the first language above.
if (!No_built_in_languages && (static_cast<int>(Lcl_languages.size()) == 1)) {
for (int i=1; i<NUM_BUILTIN_LANGUAGES; i++) {
Lcl_languages.push_back(Lcl_builtin_languages[i]);
// if we only have one language at this point, we need to setup the builtin languages as we might be dealing with an old style strings.tbl
// which doesn't support anything beyond the builtin languages. Note, we start at i = 1 because we added the first language above.
if (!No_built_in_languages && (static_cast<int>(Lcl_languages.size()) == 1)) {
for (int i=1; i<NUM_BUILTIN_LANGUAGES; i++) {
Lcl_languages.push_back(Lcl_builtin_languages[i]);
}
}
}

Expand Down Expand Up @@ -279,6 +284,8 @@ void lcl_init(int lang_init)

void lcl_close() {
lcl_xstr_close();

Lcl_languages.clear();
}

// parses the string.tbl to see which languages are supported. Doesn't read in any strings.
Expand Down Expand Up @@ -602,6 +609,9 @@ void lcl_delayed_xstr(SCP_string& str, const char* name, int xstr) {
// initialize the xstr table
void lcl_xstr_init()
{
if (Xstr_tables_parsed)
return;

Xstr_table_map.clear();

Assertion(Lcl_ext_str.empty() && Lcl_ext_str_explicit_default.empty(), "Localize system was not shut down properly!");
Expand Down Expand Up @@ -666,6 +676,7 @@ void lcl_xstr_init()
parse_modular_table(NOX("*-tlc.tbm"), parse_tstringstbl);


Xstr_tables_parsed = true;
Xstr_inited = true;

lcl_delayed_xstr_internal(std::nullopt);
Expand Down Expand Up @@ -695,6 +706,9 @@ void lcl_xstr_close()
}
}
Lcl_ext_str_explicit_default.clear();

Xstr_tables_parsed = false;
Xstr_inited = false;
}


Expand Down
10 changes: 7 additions & 3 deletions code/ship/ship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6365,6 +6365,9 @@ void ship_init()
Ship_types.erase(Ship_types.begin() + idx);
}

Fighter_bomber_valid = false;
Ship_type_fighter = Ship_type_bomber = Ship_type_fighter_bomber = -1;

// See whether this mod defines an explicit "fighter/bomber" type (which would take priority over the special usage), and if not, whether the component types exist
if (ship_type_name_lookup(Fighter_bomber_type_name) < 0)
{
Expand Down Expand Up @@ -6411,6 +6414,7 @@ void ship_init()
//Parse main TBL first
Removed_ships.clear();
Ship_info.clear();
Wing_formations.clear();
Hud_parsed_ships.clear();
parse_shiptbl("ships.tbl");

Expand Down Expand Up @@ -16834,9 +16838,7 @@ int ship_find_repair_ship( object *requester_obj, object **ship_we_found )
}

/**
* Called in game_shutdown() to free malloced memory
*
* NOTE: do not call this function. It is only called from ::game_shutdown()
* Frees the ship tables and other memory allocated by ship_init()
*/
void ship_close()
{
Expand All @@ -16860,6 +16862,8 @@ void ship_close()
Ship_types[i].ai_actively_pursues_temp.clear();
}
Ship_types.clear();

Ships_inited = false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion code/ship/ship.h
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,7 @@ extern void ship_wing_cleanup( int shipnum, wing *wingp );
extern void wing_maybe_cleanup( wing *wingp, int team = -1 );

extern int ship_find_repair_ship( object *requester_obj, object **ship_we_found = NULL );
extern void ship_close(); // called in game_shutdown() to free malloced memory
extern void ship_close(); // frees the ship tables


extern void ship_assign_sound_all();
Expand Down
2 changes: 1 addition & 1 deletion code/weapon/weapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ inline int weapon_info_size()

void weapon_init(); // called at game startup
void weapon_post_ship_init(); // called after ship_init() to resolve mine proximity ship type/class names
void weapon_close(); // called at game shutdown
void weapon_close(); // frees the weapon tables
void weapon_level_init(); // called before the start of each level
void weapon_render(object* obj, model_draw_list *scene);
void weapon_delete( object * obj );
Expand Down
7 changes: 6 additions & 1 deletion code/weapon/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5150,6 +5150,9 @@ void weapon_init()
{
if ( !Weapons_inited ) {
Spawn_names.clear();
Pending_proximity_type_names.clear();
Pending_proximity_class_names.clear();
Default_cmeasure_name[0] = '\0';

// parse weapons.tbl
Removed_weapons.clear();
Expand All @@ -5174,7 +5177,7 @@ void weapon_init()


/**
* Call from game_shutdown() only!!
* Frees the weapon tables
*/
void weapon_close()
{
Expand All @@ -5191,6 +5194,8 @@ void weapon_close()
}

Spawn_names.clear();

Weapons_inited = false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion freespace2/freespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7166,7 +7166,7 @@ void game_shutdown(void)
Cmdline_mod = nullptr;
}

lcl_xstr_close();
lcl_close();

threading::shut_down_task_pool();
}
Expand Down
8 changes: 4 additions & 4 deletions test/src/options/test_options_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ TEST_F(OptionsManagerOverride, LaterOverrideReplacesEarlierOne)
// type) rather than getCurrentValueDescription(), because several options' display functions call XSTR() for
// localized display strings (e.g. "On"/"Off", the shadow quality tiers). XSTR() hits an Int3() unless
// lcl_xstr_init() ran first, and the OptionsManagerOverride fixture never runs it. Only FSTestFixture does,
// and Xstr_inited stays set for the rest of the process afterwards, so under --gtest_shuffle a display call
// from this fixture crashes or passes purely by test order. getValue() only exercises the deserializer, which
// is exactly the contract these tests are checking anyway. The one test that must go through a display
// function uses the OptionsManagerOverrideLocalized fixture below instead.
// and its teardown resets Xstr_inited, so a display call from this fixture would hit the Int3() regardless
// of test order. getValue() only exercises the deserializer, which is exactly the contract these tests are
// checking anyway. The one test that must go through a display function uses the
// OptionsManagerOverrideLocalized fixture below instead.

TEST_F(OptionsManagerOverride, BoolOverrideRoundTrips)
{
Expand Down
Loading