Skip to content

Commit d57202f

Browse files
committed
Favor contains over count
- Use contains(key) for maps instead of count(key) - Also streamline a tingle statue patch Will work on the other uses of count at a later time, might do it alongside some other changes
1 parent cbe3bfc commit d57202f

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

command/RandoSession.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ std::shared_ptr<RandoSession::CacheEntry> RandoSession::getEntry(const std::vect
470470
resultKey = cacheKey + element;
471471
}
472472
// if we've already cached this
473-
if (parentEntry->children.count(resultKey) > 0)
473+
if (parentEntry->children.contains(resultKey))
474474
{
475475
cacheKey = resultKey;
476476
parentEntry = parentEntry->children.at(cacheKey);

logic/World.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ static std::stringstream lastError;
2424
#define YAML_FIELD_CHECK(ref, key, err) if(!ref[key]) {lastError << "Unable to find key: \"" << key << '"'; return err;}
2525
#define VALID_CHECK(e, invalid, msg, err) if(e == invalid) {lastError << msg; LOG_ERR_AND_RETURN(err);}
2626
#define ITEM_VALID_CHECK(item, msg) VALID_CHECK(item, GameItem::INVALID, msg, WorldLoadingError::GAME_ITEM_DOES_NOT_EXIST)
27-
#define AREA_VALID_CHECK(area, msg) VALID_CHECK(0, areaTable.count(area), msg, WorldLoadingError::AREA_DOES_NOT_EXIST)
28-
#define REGION_VALID_CHECK(region, msg) VALID_CHECK(0, hintRegions.count(region), msg, WorldLoadingError::AREA_DOES_NOT_EXIST)
29-
#define LOCATION_VALID_CHECK(loc, msg) VALID_CHECK(0, locationTable.count(loc), msg, WorldLoadingError::LOCATION_DOES_NOT_EXIST)
27+
#define AREA_VALID_CHECK(area, msg) VALID_CHECK(areaTable.contains(area), false, msg, WorldLoadingError::AREA_DOES_NOT_EXIST)
28+
#define REGION_VALID_CHECK(region, msg) VALID_CHECK(hintRegions.contains(region), false, msg, WorldLoadingError::AREA_DOES_NOT_EXIST)
29+
#define LOCATION_VALID_CHECK(loc, msg) VALID_CHECK(locationTable.contains(loc), false, msg, WorldLoadingError::LOCATION_DOES_NOT_EXIST)
3030
#define VALID_DUNGEON_CHECK(dungeon) if (!isValidDungeon(dungeon)) {ErrorLog::getInstance().log("Unrecognized dungeon name: \"" + dungeon + "\""); LOG_ERR_AND_RETURN(WorldLoadingError::INVALID_DUNGEON_NAME)};
3131

3232
int World::eventCounter = 0;

tweaks.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ TweakError fix_shop_item_y_offsets() {
10981098
CAST_ENTRY_TO_FILETYPE(elf, FileTypes::ELF, data)
10991099
const float y_offset = elfUtil::read_float(elf, elfUtil::AddressToOffset(elf, display_data_addr + 0x10));
11001100

1101-
if (y_offset == 0.0f && ArrowID.count(id) == 0) {
1101+
if (y_offset == 0.0f && !ArrowID.contains(id)) {
11021102
// If the item didn't originally have a Y offset we need to give it one so it's not sunken into the pedestal.
11031103
// Only exception are for items 10 11 and 12 - arrow refill pickups. Those have no Y offset but look fine already.
11041104
static constexpr float new_y_offset = 20.0f;
@@ -2655,15 +2655,15 @@ TweakError add_barren_dungeon_hint_triggers(World& world) {
26552655

26562656
TweakError update_tingle_statue_item_get_funcs() {
26572657
const uint32_t item_get_func_ptr = 0x0001DA54; // First relevant relocation entry in .rela.data (overwrites .data section when loaded)
2658-
const std::unordered_map<int, std::string> symbol_name_by_item_id = { {0xA3, "dragon_tingle_statue_item_get_func"}, {0xA4, "forbidden_tingle_statue_item_get_func"}, {0xA5, "goddess_tingle_statue_item_get_func"}, {0xA6, "earth_tingle_statue_item_get_func"}, {0xA7, "wind_tingle_statue_item_get_func"} };
2658+
const std::unordered_map<uint8_t, std::string> symbol_name_by_item_id = { {0xA3, "dragon_tingle_statue_item_get_func"}, {0xA4, "forbidden_tingle_statue_item_get_func"}, {0xA5, "goddess_tingle_statue_item_get_func"}, {0xA6, "earth_tingle_statue_item_get_func"}, {0xA7, "wind_tingle_statue_item_get_func"} };
26592659
RandoSession::CacheEntry& rpx = g_session.openGameFile("code/cking.rpx@RPX@ELF");
26602660

2661-
for (const uint8_t statue_id : {0xA3, 0xA4, 0xA5, 0xA6, 0xA7}) {
2662-
if(custom_symbols.count(symbol_name_by_item_id.at(statue_id)) == 0) LOG_ERR_AND_RETURN(TweakError::MISSING_SYMBOL);
2661+
for (const auto& [statue_id, symbol] : symbol_name_by_item_id) {
2662+
if(!custom_symbols.contains(symbol)) LOG_ERR_AND_RETURN(TweakError::MISSING_SYMBOL);
26632663

26642664
const uint32_t item_func_addr = item_get_func_ptr + (statue_id * 0xC) + 8;
2665-
const uint32_t item_func_ptr = custom_symbols.at(symbol_name_by_item_id.at(statue_id));
2666-
2665+
const uint32_t item_func_ptr = custom_symbols.at(symbol);
2666+
26672667
rpx.addAction([=](RandoSession* session, FileType* data) -> int {
26682668
CAST_ENTRY_TO_FILETYPE(elf, FileTypes::ELF, data)
26692669

0 commit comments

Comments
 (0)