fix: fix clean task

This commit is contained in:
Tsubasa6848
2024-02-23 21:07:06 +08:00
Unverified
parent 5efa2ab484
commit 7a19e82fb5
4 changed files with 23 additions and 13 deletions
+15 -5
View File
@@ -12,7 +12,8 @@ bool mSendToast = true;
namespace Cleaner {
static std::shared_ptr<ll::schedule::task::Task<ll::chrono::ServerClock>> mAutoCleanTask;
static std::shared_ptr<ll::schedule::task::Task<ll::chrono::ServerClock>> mCheckCleanTask;
static std::shared_ptr<ll::schedule::task::Task<ll::chrono::ServerClock>> mCleanTaskCount;
static std::shared_ptr<ll::schedule::task::Task<ll::chrono::ServerClock>> mCleanTaskTPS;
ServerTimeScheduler scheduler;
@@ -63,8 +64,8 @@ void AutoCleanTask(int seconds) {
mAutoCleanTask = scheduler.add<RepeatTask>(time, [] { CleanTask(); });
}
void CheckCleanTask(int max_entities, float min_tps) {
mCheckCleanTask = scheduler.add<RepeatTask>(10s, [max_entities, min_tps] {
void CleanTaskCount(int max_entities) {
mCleanTaskCount = scheduler.add<RepeatTask>(10s, [max_entities] {
auto count = CountEntities();
if (auto_clean_triggerred == false) {
if (count >= max_entities) {
@@ -79,7 +80,15 @@ void CheckCleanTask(int max_entities, float min_tps) {
Helper::broadcastToast(tr("cleaner.output.triggerAutoCleanCount", {S(count)}));
}
CleanTask();
} else if (GMLIB_Level::getLevel()->getServerAverageTps() <= min_tps) {
}
}
});
}
void CleanTaskTPS(float min_tps) {
mCleanTaskTPS = scheduler.add<RepeatTask>(10s, [min_tps] {
if (auto_clean_triggerred == false) {
if (GMLIB_Level::getLevel()->getServerAverageTps() <= min_tps) {
auto_clean_triggerred = true;
auto mspt = S(GMLIB_Level::getLevel()->getServerAverageTps());
if (ConfigFile::mConsoleLog) {
@@ -98,7 +107,8 @@ void CheckCleanTask(int max_entities, float min_tps) {
}
void stopAllTasks() {
mCheckCleanTask->cancel();
mCleanTaskTPS->cancel();
mCleanTaskCount->cancel();
mAutoCleanTask->cancel();
}
+5 -6
View File
@@ -6,12 +6,11 @@ void loadCleaner() {
if (Config->getValue<bool>({"ScheduleClean", "Enabled"}, false)) {
Cleaner::AutoCleanTask(Config->getValue<int>({"ScheduleClean", "CleanInterval"}, 3000));
}
if (Config->getValue<bool>({"AutoCleanCount", "Enabled"}, false)
|| Config->getValue<bool>({"AutoCleanTPS", "Enabled"}, false)) {
Cleaner::CheckCleanTask(
Config->getValue<int>({"AutoCleanCount", "TriggerCount"}, 900),
Config->getValue<int>({"AutoCleanTPS", "TriggerTPS"}, 15)
);
if (Config->getValue<bool>({"AutoCleanCount", "Enabled"}, false)) {
Cleaner::CleanTaskCount(Config->getValue<int>({"AutoCleanCount", "TriggerCount"}, 900));
}
if (Config->getValue<bool>({"AutoCleanTPS", "Enabled"}, false)) {
Cleaner::CleanTaskTPS(Config->getValue<float>({"AutoCleanTPS", "TriggerTPS"}, 15.0f));
}
ConfigFile::mItemDespawnTicks = Config->getValue<int>({"ItemDespawn", "DespawnTime"}, 6000);
ConfigFile::mAnnounce = Config->getValue<bool>({"Basic", "SendBroadcast"}, true);
+2 -1
View File
@@ -12,7 +12,8 @@ extern int ExecuteClean();
extern int CountEntities();
extern void AutoCleanTask(int seconds);
extern void CheckCleanTask(int max_entities, float min_tps);
extern void CleanTaskCount(int max_entities);
extern void CleanTaskTPS(float min_tps);
extern void ListenEvents();
extern void stopAllTasks();
extern void CleanTask();