use make_shared where appropriate
This commit is contained in:
@@ -2261,7 +2261,7 @@ CardIndex::CardIndex(
|
||||
continue;
|
||||
}
|
||||
|
||||
shared_ptr<CardEntry> entry(new CardEntry({defs[x], "", "", "", {}}));
|
||||
auto entry = make_shared<CardEntry>(CardEntry{defs[x], "", "", "", {}});
|
||||
if (!this->card_definitions.emplace(entry->def.card_id, entry).second) {
|
||||
throw runtime_error(string_printf(
|
||||
"duplicate card id: %08" PRIX32, entry->def.card_id.load()));
|
||||
@@ -2391,12 +2391,12 @@ MapIndex::VersionedMap::VersionedMap(std::string&& compressed_data, uint8_t lang
|
||||
"decompressed data size is incorrect (expected %zu bytes, read %zu bytes)",
|
||||
sizeof(MapDefinition), decompressed.size()));
|
||||
}
|
||||
this->map.reset(new MapDefinition(*reinterpret_cast<const MapDefinition*>(decompressed.data())));
|
||||
this->map = make_shared<MapDefinition>(*reinterpret_cast<const MapDefinition*>(decompressed.data()));
|
||||
}
|
||||
|
||||
shared_ptr<const MapDefinitionTrial> MapIndex::VersionedMap::trial() const {
|
||||
if (!this->trial_map) {
|
||||
this->trial_map.reset(new MapDefinitionTrial(*this->map));
|
||||
this->trial_map = make_shared<MapDefinitionTrial>(*this->map);
|
||||
}
|
||||
return this->trial_map;
|
||||
}
|
||||
@@ -2465,7 +2465,7 @@ MapIndex::MapIndex(const string& directory) {
|
||||
string compressed_data;
|
||||
shared_ptr<MapDefinition> decompressed_data;
|
||||
if (ends_with(filename, ".mnmd") || ends_with(filename, ".bind")) {
|
||||
decompressed_data.reset(new MapDefinition(load_object_file<MapDefinition>(directory + "/" + filename)));
|
||||
decompressed_data = make_shared<MapDefinition>(load_object_file<MapDefinition>(directory + "/" + filename));
|
||||
base_filename = filename.substr(0, filename.size() - 5);
|
||||
} else if (ends_with(filename, ".mnm") || ends_with(filename, ".bin")) {
|
||||
compressed_data = load_file(directory + "/" + filename);
|
||||
@@ -2502,9 +2502,9 @@ MapIndex::MapIndex(const string& directory) {
|
||||
|
||||
shared_ptr<VersionedMap> vm;
|
||||
if (decompressed_data) {
|
||||
vm.reset(new VersionedMap(decompressed_data, language));
|
||||
vm = make_shared<VersionedMap>(decompressed_data, language);
|
||||
} else if (!compressed_data.empty()) {
|
||||
vm.reset(new VersionedMap(std::move(compressed_data), language));
|
||||
vm = make_shared<VersionedMap>(std::move(compressed_data), language);
|
||||
} else {
|
||||
throw runtime_error("unknown map file format");
|
||||
}
|
||||
@@ -2512,7 +2512,7 @@ MapIndex::MapIndex(const string& directory) {
|
||||
string name = vm->map->name.decode(vm->language);
|
||||
auto map_it = this->maps.find(vm->map->map_number);
|
||||
if (map_it == this->maps.end()) {
|
||||
map_it = this->maps.emplace(vm->map->map_number, new Map(vm)).first;
|
||||
map_it = this->maps.emplace(vm->map->map_number, make_shared<Map>(vm)).first;
|
||||
static_game_data_log.info("(%s) Created Episode 3 map %08" PRIX32 " %c (%s; %s)",
|
||||
filename.c_str(),
|
||||
vm->map->map_number.load(),
|
||||
@@ -2640,7 +2640,7 @@ COMDeckIndex::COMDeckIndex(const string& filename) {
|
||||
try {
|
||||
auto json = JSON::parse(load_file(filename));
|
||||
for (const auto& def_json : json.as_list()) {
|
||||
auto& def = this->decks.emplace_back(new COMDeckDefinition());
|
||||
auto& def = this->decks.emplace_back(make_shared<COMDeckDefinition>());
|
||||
def->index = this->decks.size() - 1;
|
||||
def->player_name = def_json->at(0).as_string();
|
||||
def->deck_name = def_json->at(1).as_string();
|
||||
|
||||
@@ -48,10 +48,7 @@ void PlayerState::init() {
|
||||
throw logic_error("replacing a player state object is not permitted");
|
||||
}
|
||||
|
||||
this->deck_state.reset(new DeckState(
|
||||
this->client_id,
|
||||
s->deck_entries[client_id]->card_ids,
|
||||
s->options.random_crypt));
|
||||
this->deck_state = make_shared<DeckState>(this->client_id, s->deck_entries[client_id]->card_ids, s->options.random_crypt);
|
||||
if (s->map_and_rules->rules.disable_deck_shuffle) {
|
||||
this->deck_state->disable_shuffle();
|
||||
}
|
||||
@@ -77,10 +74,10 @@ void PlayerState::init() {
|
||||
throw runtime_error("SC card is not a Hunters or Arkz SC");
|
||||
}
|
||||
|
||||
this->hand_and_equip.reset(new HandAndEquipState());
|
||||
this->card_short_statuses.reset(new parray<CardShortStatus, 0x10>());
|
||||
this->set_card_action_chains.reset(new parray<ActionChainWithConds, 9>());
|
||||
this->set_card_action_metadatas.reset(new parray<ActionMetadata, 9>());
|
||||
this->hand_and_equip = make_shared<HandAndEquipState>();
|
||||
this->card_short_statuses = make_shared<parray<CardShortStatus, 0x10>>();
|
||||
this->set_card_action_chains = make_shared<parray<ActionChainWithConds, 9>>();
|
||||
this->set_card_action_metadatas = make_shared<parray<ActionMetadata, 9>>();
|
||||
|
||||
this->hand_and_equip->clear_FF();
|
||||
for (size_t z = 0; z < 0x10; z++) {
|
||||
@@ -91,11 +88,7 @@ void PlayerState::init() {
|
||||
this->set_card_action_metadatas->at(z).clear_FF();
|
||||
}
|
||||
|
||||
this->sc_card.reset(new Card(
|
||||
this->deck_state->sc_card_id(),
|
||||
this->sc_card_ref,
|
||||
this->client_id,
|
||||
s));
|
||||
this->sc_card = make_shared<Card>(this->deck_state->sc_card_id(), this->sc_card_ref, this->client_id, s);
|
||||
this->sc_card->init();
|
||||
this->draw_initial_hand();
|
||||
|
||||
@@ -1232,8 +1225,7 @@ bool PlayerState::set_card_from_hand(
|
||||
auto s = this->server();
|
||||
|
||||
if (!skip_error_checks_and_atk_sub) {
|
||||
int32_t code = this->error_code_for_client_setting_card(
|
||||
card_ref, card_index, loc, assist_target_client_id);
|
||||
int32_t code = this->error_code_for_client_setting_card(card_ref, card_index, loc, assist_target_client_id);
|
||||
if (code) {
|
||||
s->ruler_server->error_code1 = code;
|
||||
this->update_hand_and_equip_state_and_send_6xB4x02_if_needed();
|
||||
@@ -1248,8 +1240,7 @@ bool PlayerState::set_card_from_hand(
|
||||
}
|
||||
|
||||
if (!skip_error_checks_and_atk_sub) {
|
||||
int16_t cost = s->ruler_server->set_cost_for_card(
|
||||
this->client_id, card_ref);
|
||||
int16_t cost = s->ruler_server->set_cost_for_card(this->client_id, card_ref);
|
||||
this->subtract_atk_points(cost);
|
||||
}
|
||||
|
||||
@@ -1261,11 +1252,7 @@ bool PlayerState::set_card_from_hand(
|
||||
return 0;
|
||||
}
|
||||
this->card_refs[card_index + 1] = card_ref;
|
||||
this->set_cards[card_index - 7].reset(new Card(
|
||||
s->card_id_for_card_ref(card_ref),
|
||||
card_ref,
|
||||
this->client_id,
|
||||
s));
|
||||
this->set_cards[card_index - 7] = make_shared<Card>(s->card_id_for_card_ref(card_ref), card_ref, this->client_id, s);
|
||||
auto new_card = this->set_cards[card_index - 7];
|
||||
new_card->init();
|
||||
|
||||
|
||||
@@ -75,32 +75,32 @@ Server::~Server() noexcept(false) {
|
||||
}
|
||||
|
||||
void Server::init() {
|
||||
this->map_and_rules.reset(new MapAndRulesState());
|
||||
this->map_and_rules = make_shared<MapAndRulesState>();
|
||||
this->num_clients_present = 0;
|
||||
this->overlay_state.clear();
|
||||
for (size_t z = 0; z < 4; z++) {
|
||||
this->presence_entries[z].clear();
|
||||
this->deck_entries[z].reset(new DeckEntry());
|
||||
this->deck_entries[z] = make_shared<DeckEntry>();
|
||||
this->name_entries[z].clear();
|
||||
this->name_entries_valid[z] = false;
|
||||
}
|
||||
|
||||
this->card_special.reset(new CardSpecial(this->shared_from_this()));
|
||||
this->card_special = make_shared<CardSpecial>(this->shared_from_this());
|
||||
|
||||
// Note: The original implementation calls the default PSOV2Encryption
|
||||
// constructor for random_crypt, which just uses 0 as the seed. It then
|
||||
// re-seeds the generator later. We instead expect the caller to provide a
|
||||
// seeded generator, and we don't re-seed it at all.
|
||||
// this->random_crypt.reset(new PSOV2Encryption(0));
|
||||
// this->random_crypt = make_shared<PSOV2Encryption>(0);
|
||||
|
||||
this->state_flags.reset(new StateFlags());
|
||||
this->state_flags = make_shared<StateFlags>();
|
||||
|
||||
this->clear_player_flags_after_dice_phase();
|
||||
|
||||
this->update_battle_state_flags_and_send_6xB4x03_if_needed();
|
||||
|
||||
this->assist_server.reset(new AssistServer(this->shared_from_this()));
|
||||
this->ruler_server.reset(new RulerServer(this->shared_from_this()));
|
||||
this->assist_server = make_shared<AssistServer>(this->shared_from_this());
|
||||
this->ruler_server = make_shared<RulerServer>(this->shared_from_this());
|
||||
this->ruler_server->link_objects(this->map_and_rules, this->state_flags, this->assist_server);
|
||||
|
||||
this->send_6xB4x46();
|
||||
@@ -1403,7 +1403,7 @@ void Server::setup_and_start_battle() {
|
||||
if (!this->check_presence_entry(z)) {
|
||||
this->name_entries[z].clear();
|
||||
} else {
|
||||
this->player_states[z].reset(new PlayerState(z, this->shared_from_this()));
|
||||
this->player_states[z] = make_shared<PlayerState>(z, this->shared_from_this());
|
||||
this->player_states[z]->init();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,10 +364,8 @@ void Tournament::init() {
|
||||
is_registration_complete = this->source_json.get_bool("is_registration_complete");
|
||||
|
||||
for (const auto& team_json : this->source_json.get_list("teams")) {
|
||||
auto& team = this->teams.emplace_back(new Team(
|
||||
this->shared_from_this(),
|
||||
this->teams.size(),
|
||||
team_json->get_int("max_players")));
|
||||
auto& team = this->teams.emplace_back(make_shared<Team>(
|
||||
this->shared_from_this(), this->teams.size(), team_json->get_int("max_players")));
|
||||
team->name = team_json->get_string("name");
|
||||
team->password = team_json->get_string("password");
|
||||
team_index_to_rounds_cleared.emplace_back(team_json->get_int("num_rounds_cleared"));
|
||||
@@ -806,7 +804,7 @@ TournamentIndex::TournamentIndex(
|
||||
}
|
||||
for (size_t z = 0; z < min<size_t>(json.size(), 0x20); z++) {
|
||||
if (!json.at(z).is_null()) {
|
||||
shared_ptr<Tournament> tourn(new Tournament(this->map_index, this->com_deck_index, json.at(z)));
|
||||
auto tourn = make_shared<Tournament>(this->map_index, this->com_deck_index, json.at(z));
|
||||
tourn->init();
|
||||
if (!this->name_to_tournament.emplace(tourn->get_name(), tourn).second) {
|
||||
throw runtime_error("multiple tournaments have the same name: " + tourn->get_name());
|
||||
@@ -820,7 +818,7 @@ TournamentIndex::TournamentIndex(
|
||||
throw runtime_error("tournament JSON dict length is incorrect");
|
||||
}
|
||||
for (const auto& it : json.as_dict()) {
|
||||
shared_ptr<Tournament> tourn(new Tournament(this->map_index, this->com_deck_index, *it.second));
|
||||
auto tourn = make_shared<Tournament>(this->map_index, this->com_deck_index, *it.second);
|
||||
tourn->init();
|
||||
if (!this->name_to_tournament.emplace(tourn->get_name(), tourn).second) {
|
||||
// This is logic_error instead of runtime_error because JSON dicts are
|
||||
|
||||
Reference in New Issue
Block a user