mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 01:40:46 +08:00
refactor: 重构战斗,抽出BattleHelper基类(还没写完,睡觉要紧)
1>D:\Code\MeoAssistantArknights\src\MaaCore\Task\AbstractTask.cpp(25,1): error C2220: 以下警告被视为错误 1>D:\Code\MeoAssistantArknights\src\MaaCore\Task\AbstractTask.cpp(24,17): warning C4589: 抽象类“asst::AbstractTask”的构造函数忽略虚拟基类“asst::InstHelper”的初始化设定值 1>D:\Code\MeoAssistantArknights\src\MaaCore\Task\AbstractTask.cpp(24,17): message : 虚拟基类仅由最底层派生类型进行初始化
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "InstHelper.h"
|
||||
|
||||
#include "Assistant.h"
|
||||
#include "Utils/Logger.hpp"
|
||||
|
||||
asst::InstHelper::InstHelper(asst::Assistant* inst) : m_inst(inst) {}
|
||||
|
||||
@@ -15,4 +16,29 @@ std::shared_ptr<asst::Status> asst::InstHelper::status() const
|
||||
bool asst::InstHelper::need_exit() const
|
||||
{
|
||||
return m_inst ? m_inst->need_exit() : false;
|
||||
}
|
||||
}
|
||||
|
||||
bool asst::InstHelper::sleep(unsigned millisecond) const
|
||||
{
|
||||
if (need_exit()) {
|
||||
return false;
|
||||
}
|
||||
if (millisecond == 0) {
|
||||
std::this_thread::yield();
|
||||
return true;
|
||||
}
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
Log.trace("ready to sleep", millisecond);
|
||||
auto millisecond_ms = std::chrono::milliseconds(millisecond);
|
||||
auto interval = millisecond_ms / 5;
|
||||
|
||||
while (!need_exit()) {
|
||||
std::this_thread::sleep_for(interval);
|
||||
if (std::chrono::steady_clock::now() - start > millisecond_ms) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Log.trace("end of sleep", millisecond);
|
||||
|
||||
return !need_exit();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user