mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2025-10-30 08:01:01 +00:00
remove some double lookups in dynos
This commit is contained in:
parent
7dc31e3780
commit
a67c096ecb
3 changed files with 40 additions and 26 deletions
|
|
@ -27,16 +27,20 @@ public:
|
|||
|
||||
void* get(int64_t key) {
|
||||
switch (mMapType) {
|
||||
case MapType::Ordered:
|
||||
if (mOrderedMap->count(key)) {
|
||||
return mOrderedMap->at(key);
|
||||
case MapType::Ordered: {
|
||||
auto it = mOrderedMap->find(key);
|
||||
if (it != mOrderedMap->end()) {
|
||||
return it->second;
|
||||
}
|
||||
break;
|
||||
case MapType::Unordered:
|
||||
if (mUnorderedMap->count(key)) {
|
||||
return mUnorderedMap->at(key);
|
||||
}
|
||||
case MapType::Unordered: {
|
||||
auto it = mUnorderedMap->find(key);
|
||||
if (it != mUnorderedMap->end()) {
|
||||
return it->second;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,8 +150,9 @@ ActorGfx* DynOS_Actor_GetActorGfx(const GraphNode* aGraphNode) {
|
|||
|
||||
// If georef is not NULL, check georef
|
||||
if (aGraphNode->georef != NULL) {
|
||||
if (_ValidActors.count(aGraphNode->georef) != 0) {
|
||||
return &_ValidActors[aGraphNode->georef];
|
||||
auto it = _ValidActors.find(aGraphNode->georef);
|
||||
if (it != _ValidActors.end()) {
|
||||
return &it->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -177,10 +178,11 @@ void DynOS_Actor_Valid(const void* aGeoref, ActorGfx& aActorGfx) {
|
|||
void DynOS_Actor_Invalid(const void* aGeoref, s32 aPackIndex) {
|
||||
if (aGeoref == NULL) { return; }
|
||||
auto& _ValidActors = DynosValidActors();
|
||||
if (_ValidActors.count(aGeoref) == 0) { return; }
|
||||
if (_ValidActors[aGeoref].mPackIndex != aPackIndex) { return; }
|
||||
auto it = _ValidActors.find(aGeoref);
|
||||
if (it == _ValidActors.end()) { return; }
|
||||
if (it->second.mPackIndex != aPackIndex) { return; }
|
||||
|
||||
DynOS_Tex_Invalid(_ValidActors[aGeoref].mGfxData);
|
||||
DynOS_Tex_Invalid(it->second.mGfxData);
|
||||
_ValidActors.erase(aGeoref);
|
||||
}
|
||||
|
||||
|
|
@ -191,7 +193,8 @@ void DynOS_Actor_Override(struct Object* obj, void** aSharedChild) {
|
|||
if (georef == NULL) { return; }
|
||||
|
||||
auto& _ValidActors = DynosValidActors();
|
||||
if (_ValidActors.count(georef) == 0) { return; }
|
||||
auto it = _ValidActors.find(georef);
|
||||
if (it == _ValidActors.end()) { return; }
|
||||
|
||||
// Check if the behavior uses a character specific model
|
||||
if (obj && (obj->behavior == smlua_override_behavior(bhvMario) ||
|
||||
|
|
@ -206,7 +209,7 @@ void DynOS_Actor_Override(struct Object* obj, void** aSharedChild) {
|
|||
}
|
||||
|
||||
|
||||
*aSharedChild = (void*)_ValidActors[georef].mGraphNode;
|
||||
*aSharedChild = (void*)it->second.mGraphNode;
|
||||
}
|
||||
|
||||
void DynOS_Actor_Override_All(void) {
|
||||
|
|
|
|||
|
|
@ -159,8 +159,9 @@ struct GraphNode* DynOS_Model_StoreGeo(u32* aId, enum ModelPool aModelPool, void
|
|||
}
|
||||
|
||||
struct GraphNode* DynOS_Model_GetErrorGeo() {
|
||||
if (!sIdMap.count(MODEL_ERROR_MODEL)) { return NULL; }
|
||||
auto& vec = sIdMap[MODEL_ERROR_MODEL];
|
||||
auto it = sIdMap.find(MODEL_ERROR_MODEL);
|
||||
if (it == sIdMap.end()) { return NULL; }
|
||||
auto& vec = it->second;
|
||||
if (vec.size() == 0 || vec.empty()) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -170,15 +171,17 @@ struct GraphNode* DynOS_Model_GetErrorGeo() {
|
|||
struct GraphNode* DynOS_Model_GetGeo(u32 aId) {
|
||||
if (!aId) { return NULL; }
|
||||
|
||||
if (sOverwriteMap.count(aId)) {
|
||||
aId = sOverwriteMap[aId];
|
||||
auto overwriteIt = sOverwriteMap.find(aId);
|
||||
if (overwriteIt != sOverwriteMap.end()) {
|
||||
aId = overwriteIt->second;
|
||||
}
|
||||
|
||||
if (sIdMap.count(aId) == 0) {
|
||||
auto idIt = sIdMap.find(aId);
|
||||
if (idIt == sIdMap.end()) {
|
||||
return DynOS_Model_GetErrorGeo();
|
||||
}
|
||||
|
||||
auto& vec = sIdMap[aId];
|
||||
auto& vec = idIt->second;
|
||||
if (vec.size() == 0 || vec.empty()) {
|
||||
return DynOS_Model_GetErrorGeo();
|
||||
}
|
||||
|
|
@ -225,11 +228,14 @@ u32 DynOS_Model_GetIdFromAsset(void* asset) {
|
|||
if (!asset) { return MODEL_NONE; }
|
||||
u32 lowest = 9999;
|
||||
for (int i = 0; i < MODEL_POOL_MAX; i++) {
|
||||
if (!sAssetMap[i].count(asset)) { continue; }
|
||||
u32 id = sAssetMap[i][asset].id;
|
||||
auto& map = sAssetMap[i];
|
||||
auto assetIt = map.find(asset);
|
||||
if (assetIt == map.end()) { continue; }
|
||||
u32 id = assetIt->second.id;
|
||||
if (id < lowest) { lowest = id; }
|
||||
if (sOverwriteMap.count(id)) {
|
||||
id = sOverwriteMap[id];
|
||||
auto idIt = sOverwriteMap.find(id);
|
||||
if (idIt != sOverwriteMap.end()) {
|
||||
id = idIt->second;
|
||||
if (id < lowest) { lowest = id; }
|
||||
}
|
||||
}
|
||||
|
|
@ -337,17 +343,18 @@ void DynOS_Model_ClearPool(enum ModelPool aModelPool) {
|
|||
auto& assetMap = sAssetMap[aModelPool];
|
||||
for (auto& asset : assetMap) {
|
||||
auto& info = asset.second;
|
||||
if (sIdMap.count(info.id) == 0) { continue; }
|
||||
auto idIt = sIdMap.find(info.id);
|
||||
if (idIt == sIdMap.end()) { continue; }
|
||||
auto& idMap = idIt->second;
|
||||
|
||||
// preventing clearing permanent vanilla model slot
|
||||
if (info.id <= VANILLA_ID_END && sIdMap.count(info.id) <= 1) {
|
||||
if (info.id <= VANILLA_ID_END && idMap.size() <= 1) {
|
||||
if (sAssetMap[MODEL_POOL_PERMANENT].count(info.asset) > 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// erase from id map
|
||||
auto& idMap = sIdMap[info.id];
|
||||
for (auto info2 = idMap.begin(); info2 != idMap.end(); ) {
|
||||
if (info.id == info2->id && info2->modelPool == aModelPool) {
|
||||
info2 = idMap.erase(info2);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue