Store time in turn execution on battle class.
continuous-integration/drone/push Build is passing Details

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2020-08-28 12:24:10 +02:00
parent d2e72deeca
commit 32f75f4a47
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
3 changed files with 9 additions and 1 deletions

View File

@ -78,4 +78,6 @@ export bool CreatureLib_Battle_HasVolatileScript(Battle* p, const char* key) {
export uint8_t CreatureLib_Battle_RegisterEventListener(Battle* p, void (*func)(const EventData*)) {
Try(p->RegisterEventListener(func);)
}
export const HistoryHolder* CreatureLib_Battle_GetHistory(Battle* p) { return &p->GetHistory(); }
export const HistoryHolder* CreatureLib_Battle_GetHistory(Battle* p) { return &p->GetHistory(); }
SIMPLE_GET_FUNC(Battle, GetLastTurnTimeMicroseconds, long);

View File

@ -46,6 +46,7 @@ void Battle::CheckChoicesSetAndRun() {
THROW("Exception during choices set validation: '" << e.what() << "'.")
}
auto begin = std::chrono::steady_clock::now();
auto choices = std::vector<std::shared_ptr<BaseTurnChoice>>(_numberOfSides * _creaturesPerSide);
auto i = 0;
try {
@ -90,6 +91,8 @@ void Battle::CheckChoicesSetAndRun() {
this->_currentTurnQueue = nullptr;
}
TriggerEventListener<TurnEndEvent>();
auto end = std::chrono::steady_clock::now();
_lastTurnTime = std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count();
}
ArbUt::BorrowedPtr<ChoiceQueue> Battle::GetCurrentTurnQueue() const noexcept { return _currentTurnQueue; }

View File

@ -34,6 +34,7 @@ namespace CreatureLib::Battling {
uint32_t _currentTurn = 0;
ScriptSet _volatile;
long _lastTurnTime;
public:
Battle(const BattleLibrary* library, ArbUt::List<BattleParty*> parties, bool canFlee = true,
@ -113,6 +114,8 @@ namespace CreatureLib::Battling {
, "Exception occurred during history element registration.");
}
const HistoryHolder& GetHistory() const noexcept { return _historyHolder; }
long GetLastTurnTimeMicroseconds() const noexcept { return _lastTurnTime; }
};
}