Cheats: Fixed performance issue with WRAM cheats
This commit is contained in:
parent
3136cd595a
commit
6e70ab88de
2 changed files with 6 additions and 5 deletions
|
@ -13,6 +13,7 @@ CheatManager::CheatManager(Console* console)
|
|||
void CheatManager::AddCheat(CheatCode code)
|
||||
{
|
||||
_cheats.push_back(code);
|
||||
_cheatsByAddress.emplace(code.Address, code);
|
||||
_hasCheats = true;
|
||||
_bankHasCheats[code.Address >> 16] = true;
|
||||
|
||||
|
@ -70,6 +71,7 @@ void CheatManager::ClearCheats(bool showMessage)
|
|||
bool hadCheats = !_cheats.empty();
|
||||
|
||||
_cheats.clear();
|
||||
_cheatsByAddress.clear();
|
||||
_hasCheats = false;
|
||||
memset(_bankHasCheats, 0, sizeof(_bankHasCheats));
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ private:
|
|||
bool _hasCheats = false;
|
||||
bool _bankHasCheats[0x100] = {};
|
||||
vector<CheatCode> _cheats;
|
||||
unordered_map<uint32_t, CheatCode> _cheatsByAddress;
|
||||
|
||||
void AddCheat(CheatCode code);
|
||||
|
||||
|
@ -36,11 +37,9 @@ public:
|
|||
__forceinline void CheatManager::ApplyCheat(uint32_t addr, uint8_t &value)
|
||||
{
|
||||
if(_hasCheats && _bankHasCheats[addr >> 16]) {
|
||||
for(CheatCode &cheat : _cheats) {
|
||||
if(cheat.Address == addr) {
|
||||
value = cheat.Value;
|
||||
break;
|
||||
}
|
||||
auto result = _cheatsByAddress.find(addr);
|
||||
if(result != _cheatsByAddress.end()) {
|
||||
value = result->second.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue