diff --git a/src/Main.cc b/src/Main.cc index 8c5a6915..46f02c03 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -2587,7 +2587,6 @@ Action a_describe_item( Action a_name_all_items( "name-all-items", nullptr, +[](phosg::Arguments& args) { auto s = make_shared(get_config_filename(args)); - s->clear_file_caches(); s->load_config_early(); s->load_patch_indexes(); s->load_text_index(); @@ -2674,7 +2673,6 @@ Action a_print_level_stats( +[](phosg::Arguments& args) { auto s = make_shared(get_config_filename(args)); s->load_config_early(); - s->clear_file_caches(); s->load_patch_indexes(); s->load_level_tables(); @@ -2835,7 +2833,6 @@ Action a_generate_ep3_cards_html( bool no_disassembly = args.get("no-disassembly"); auto s = make_shared(get_config_filename(args)); - s->clear_file_caches(); s->load_patch_indexes(); s->load_text_index(); s->load_ep3_cards(); @@ -3133,7 +3130,6 @@ Action a_check_supermaps( auto s = make_shared(get_config_filename(args)); s->load_config_early(); - s->clear_file_caches(); s->load_patch_indexes(); s->load_set_data_tables(); s->load_maps(); @@ -3534,7 +3530,6 @@ Action a_print_free_supermap( auto s = make_shared(get_config_filename(args)); s->load_config_early(); - s->clear_file_caches(); s->load_patch_indexes(); s->load_set_data_tables(); s->load_maps(); @@ -3560,7 +3555,6 @@ Action a_check_quests( auto s = make_shared(get_config_filename(args)); s->is_debug = true; s->load_config_early(); - s->clear_file_caches(); s->load_patch_indexes(); s->load_set_data_tables(); s->load_maps(); diff --git a/src/ReceiveCommands.cc b/src/ReceiveCommands.cc index ae587c90..18c8de16 100644 --- a/src/ReceiveCommands.cc +++ b/src/ReceiveCommands.cc @@ -3320,8 +3320,8 @@ static asio::awaitable on_D7_GC(shared_ptr c, Channel::Message& ms } else { try { auto s = c->require_server_state(); - auto f = s->gba_files_cache->get_or_load("system/gba/" + filename).file; - send_open_quest_file(c, "", filename, "", 0, QuestFileType::GBA_DEMO, f->data); + auto data = std::make_shared(phosg::load_file("system/gba/" + filename)); + send_open_quest_file(c, "", filename, "", 0, QuestFileType::GBA_DEMO, data); } catch (const out_of_range&) { send_command(c, 0xD7, 0x00); } catch (const phosg::cannot_open_file&) { diff --git a/src/ServerState.cc b/src/ServerState.cc index 274ab725..4743da95 100644 --- a/src/ServerState.cc +++ b/src/ServerState.cc @@ -78,9 +78,7 @@ ServerState::ServerState(const string& config_filename, bool is_replay) io_context(make_shared(1)), config_filename(config_filename), is_replay(is_replay), - thread_pool(make_unique()), - bb_system_cache(new FileContentsCache(3600000000ULL)), - gba_files_cache(new FileContentsCache(3600000000ULL)) {} + thread_pool(make_unique()) {} void ServerState::add_client_to_available_lobby(shared_ptr c, bool allow_games) { shared_ptr added_to_lobby; @@ -611,12 +609,11 @@ void ServerState::set_port_configuration(const vector& port_c } } -shared_ptr ServerState::load_bb_file( - const string& patch_index_filename, const string& gsl_filename, const string& bb_directory_filename) const { +shared_ptr ServerState::load_bb_file(const string& filename) const { if (this->bb_patch_file_index) { // First, look in the patch tree's data directory - string patch_index_path = "./data/" + patch_index_filename; + string patch_index_path = "./data/" + filename; try { return this->bb_patch_file_index->get(patch_index_path)->load_data(); } catch (const out_of_range&) { @@ -625,17 +622,16 @@ shared_ptr ServerState::load_bb_file( if (this->bb_data_gsl) { // Second, look in the patch tree's data.gsl file - const string& effective_gsl_filename = gsl_filename.empty() ? patch_index_filename : gsl_filename; try { // TODO: It's kinda not great that we copy the data here; find a way to avoid doing this (also in the below case) - return std::make_shared(this->bb_data_gsl->get_copy(effective_gsl_filename)); + return std::make_shared(this->bb_data_gsl->get_copy(filename)); } catch (const out_of_range&) { } // Third, look in data.gsl without the filename extension - size_t dot_offset = effective_gsl_filename.rfind('.'); + size_t dot_offset = filename.rfind('.'); if (dot_offset != string::npos) { - string no_ext_gsl_filename = effective_gsl_filename.substr(0, dot_offset); + string no_ext_gsl_filename = filename.substr(0, dot_offset); try { return std::make_shared(this->bb_data_gsl->get_copy(no_ext_gsl_filename)); } catch (const out_of_range&) { @@ -644,13 +640,7 @@ shared_ptr ServerState::load_bb_file( } // Finally, look in system/blueburst - const string& effective_bb_directory_filename = bb_directory_filename.empty() ? patch_index_filename : bb_directory_filename; - try { - auto ret = this->bb_system_cache->get_or_load("system/blueburst/" + effective_bb_directory_filename); - return ret.file->data; - } catch (const exception& e) { - throw phosg::cannot_open_file(patch_index_filename); - } + return std::make_shared(phosg::load_file("system/blueburst/" + filename)); } shared_ptr ServerState::load_map_file(Version version, const string& filename) const { @@ -1853,13 +1843,6 @@ vector> ServerState::supermaps_for_variations( return ret; } -void ServerState::clear_file_caches() { - config_log.info_f("Clearing BB system cache"); - this->bb_system_cache.reset(new FileContentsCache(3600000000ULL)); - config_log.info_f("Clearing GBA file cache"); - this->gba_files_cache.reset(new FileContentsCache(300 * 1000 * 1000)); -} - void ServerState::load_set_data_tables() { config_log.info_f("Loading set data tables"); @@ -1901,19 +1884,8 @@ void ServerState::load_set_data_tables() { void ServerState::load_battle_params() { config_log.info_f("Loading JSON battle parameters"); - try { - this->battle_params = std::make_shared(phosg::JSON::parse(phosg::load_file( - "system/tables/battle-params.json"))); - } catch (const std::exception& e) { - config_log.info_f("Cannot load JSON battle parameters ({}); loading binary battle parameters", e.what()); - this->battle_params = std::make_shared( - this->load_bb_file("BattleParamEntry_on.dat"), - this->load_bb_file("BattleParamEntry_lab_on.dat"), - this->load_bb_file("BattleParamEntry_ep4_on.dat"), - this->load_bb_file("BattleParamEntry.dat"), - this->load_bb_file("BattleParamEntry_lab.dat"), - this->load_bb_file("BattleParamEntry_ep4.dat")); - } + this->battle_params = std::make_shared(phosg::JSON::parse(phosg::load_file( + "system/tables/battle-params.json"))); } void ServerState::load_level_tables() { @@ -2362,7 +2334,6 @@ void ServerState::load_all(bool enable_thread_pool) { this->load_bb_private_keys(); this->load_bb_system_defaults(); this->load_accounts(); - this->clear_file_caches(); this->load_patch_indexes(); this->load_ep3_cards(); this->load_ep3_maps(); diff --git a/src/ServerState.hh b/src/ServerState.hh index ecb9d416..6df13a72 100644 --- a/src/ServerState.hh +++ b/src/ServerState.hh @@ -195,8 +195,6 @@ struct ServerState : public std::enable_shared_from_this { std::unordered_map> supermap_for_free_play_key; std::shared_ptr room_layout_index; std::shared_ptr bb_stream_file; - std::shared_ptr bb_system_cache; - std::shared_ptr gba_files_cache; std::shared_ptr dol_file_index; std::shared_ptr ep3_card_index; std::shared_ptr ep3_card_index_trial; @@ -404,10 +402,7 @@ struct ServerState : public std::enable_shared_from_this { void set_port_configuration(const std::vector& port_configs); - std::shared_ptr load_bb_file( - const std::string& patch_index_filename, - const std::string& gsl_filename = "", - const std::string& bb_directory_filename = "") const; + std::shared_ptr load_bb_file(const std::string& patch_index_filename) const; std::shared_ptr load_map_file(Version version, const std::string& filename) const; std::shared_ptr load_map_file_uncached(Version version, const std::string& filename) const; @@ -438,7 +433,6 @@ struct ServerState : public std::enable_shared_from_this { void load_teams(); void load_patch_indexes(); void load_maps(); - void clear_file_caches(); void load_battle_params(); void load_level_tables(); void load_text_index(); diff --git a/src/ShellCommands.cc b/src/ShellCommands.cc index 367ff18f..d867746c 100644 --- a/src/ShellCommands.cc +++ b/src/ShellCommands.cc @@ -158,7 +158,6 @@ ShellCommand c_reload( accounts - reindex user accounts\n\ battle-params - reload the BB enemy stats files\n\ bb-keys - reload BB private keys\n\ - caches - clear all cached files\n\ config - reload most fields from config.json\n\ dol-files - reindex all DOL files\n\ drop-tables - reload drop tables\n\ @@ -193,8 +192,6 @@ ShellCommand c_reload( args.s->load_accounts(); } else if (type == "maps") { args.s->load_maps(); - } else if (type == "caches") { - args.s->clear_file_caches(); } else if (type == "patch-files") { args.s->load_patch_indexes(); } else if (type == "ep3-cards") {