Improve performance for setting choices.

This commit is contained in:
Deukhoofd 2019-11-06 18:08:21 +01:00
parent beac87f981
commit 19e1308f93
2 changed files with 4 additions and 6 deletions

View File

@ -5,15 +5,11 @@
using namespace CreatureLib::Battling; using namespace CreatureLib::Battling;
bool BattleSide::AllChoicesSet() const { bool BattleSide::AllChoicesSet() const {
for (uint8_t i = 0; i < _creaturesPerSide; i++){ return _choicesSet == _creaturesPerSide;
if (_choices[i] == nullptr){
return false;
}
}
return true;
} }
void BattleSide::ResetChoices() { void BattleSide::ResetChoices() {
_choicesSet = 0;
for (uint8_t i = 0; i < _creaturesPerSide; i++){ for (uint8_t i = 0; i < _creaturesPerSide; i++){
_choices[i] = nullptr; _choices[i] = nullptr;
} }
@ -29,6 +25,7 @@ void BattleSide::SetChoice(const BaseTurnChoice *choice) {
throw CreatureException("User not found"); throw CreatureException("User not found");
uint8_t index = std::distance(_creatures.begin(),find); uint8_t index = std::distance(_creatures.begin(),find);
_choices[index] = choice; _choices[index] = choice;
_choicesSet++;
} }
void BattleSide::SetCreature(Creature *creature, uint8_t index) { void BattleSide::SetCreature(Creature *creature, uint8_t index) {

View File

@ -10,6 +10,7 @@ namespace CreatureLib::Battling{
uint8_t _creaturesPerSide; uint8_t _creaturesPerSide;
std::vector<Creature*> _creatures; std::vector<Creature*> _creatures;
std::vector<const BaseTurnChoice*> _choices; std::vector<const BaseTurnChoice*> _choices;
uint8_t _choicesSet = 0;
public: public:
BattleSide(uint8_t creaturesPerSide) BattleSide(uint8_t creaturesPerSide)
: _creaturesPerSide(creaturesPerSide), _creatures(creaturesPerSide), _choices(creaturesPerSide) : _creaturesPerSide(creaturesPerSide), _creatures(creaturesPerSide), _choices(creaturesPerSide)