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

@ -79,3 +79,5 @@ export uint8_t CreatureLib_Battle_RegisterEventListener(Battle* p, void (*func)(
Try(p->RegisterEventListener(func);) 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() << "'.") 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 choices = std::vector<std::shared_ptr<BaseTurnChoice>>(_numberOfSides * _creaturesPerSide);
auto i = 0; auto i = 0;
try { try {
@ -90,6 +91,8 @@ void Battle::CheckChoicesSetAndRun() {
this->_currentTurnQueue = nullptr; this->_currentTurnQueue = nullptr;
} }
TriggerEventListener<TurnEndEvent>(); 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; } ArbUt::BorrowedPtr<ChoiceQueue> Battle::GetCurrentTurnQueue() const noexcept { return _currentTurnQueue; }

View File

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