cWorld: Fixed scheduler.
Fixes #1534. Added a test case into the Debuggers plugin.
This commit is contained in:
parent
1eae7d0ece
commit
7f8118e0cb
@ -10,9 +10,6 @@ g_ShowFoodStats = false; -- When true, each player's food stats are sent to the
|
|||||||
|
|
||||||
|
|
||||||
function Initialize(Plugin)
|
function Initialize(Plugin)
|
||||||
Plugin:SetName("Debuggers")
|
|
||||||
Plugin:SetVersion(1)
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
-- Test multiple hook handlers:
|
-- Test multiple hook handlers:
|
||||||
cPluginManager.AddHook(cPluginManager.HOOK_TICK, OnTick1);
|
cPluginManager.AddHook(cPluginManager.HOOK_TICK, OnTick1);
|
||||||
@ -68,6 +65,8 @@ function Initialize(Plugin)
|
|||||||
PM:BindCommand("/rmitem", "debuggers", HandleRMItem, "- Remove the specified item from the inventory.");
|
PM:BindCommand("/rmitem", "debuggers", HandleRMItem, "- Remove the specified item from the inventory.");
|
||||||
PM:BindCommand("/pickups", "debuggers", HandlePickups, "- Spawns random pickups around you");
|
PM:BindCommand("/pickups", "debuggers", HandlePickups, "- Spawns random pickups around you");
|
||||||
PM:BindCommand("/poof", "debuggers", HandlePoof, "- Nudges pickups close to you away from you");
|
PM:BindCommand("/poof", "debuggers", HandlePoof, "- Nudges pickups close to you away from you");
|
||||||
|
|
||||||
|
PM:BindConsoleCommand("sched", HandleConsoleSchedule, "Tests the world scheduling");
|
||||||
|
|
||||||
Plugin:AddWebTab("Debuggers", HandleRequest_Debuggers)
|
Plugin:AddWebTab("Debuggers", HandleRequest_Debuggers)
|
||||||
Plugin:AddWebTab("StressTest", HandleRequest_StressTest)
|
Plugin:AddWebTab("StressTest", HandleRequest_StressTest)
|
||||||
@ -1630,3 +1629,17 @@ end
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function HandleConsoleSchedule(a_Split)
|
||||||
|
LOG("Scheduling a task for 2 seconds in the future")
|
||||||
|
cRoot:Get():GetDefaultWorld():ScheduleTask(40,
|
||||||
|
function ()
|
||||||
|
LOG("Scheduled function is called.")
|
||||||
|
end
|
||||||
|
)
|
||||||
|
return true, "Task scheduled"
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1068,15 +1068,24 @@ void cWorld::TickScheduledTasks(void)
|
|||||||
{
|
{
|
||||||
cCSLock Lock(m_CSScheduledTasks);
|
cCSLock Lock(m_CSScheduledTasks);
|
||||||
auto WorldAge = m_WorldAge;
|
auto WorldAge = m_WorldAge;
|
||||||
std::move(
|
|
||||||
m_ScheduledTasks.begin(),
|
// Move all the due tasks from m_ScheduledTasks into Tasks:
|
||||||
std::find_if(
|
for (auto itr = m_ScheduledTasks.begin(); itr != m_ScheduledTasks.end();) // Cannot use range-basd for, we're modifying the container
|
||||||
m_ScheduledTasks.begin(),
|
{
|
||||||
m_ScheduledTasks.end(),
|
if ((*itr)->m_TargetTick < WorldAge)
|
||||||
[WorldAge] (cScheduledTaskPtr & Task) { return (Task->m_TargetTick < WorldAge);}
|
{
|
||||||
),
|
auto next = itr;
|
||||||
std::back_inserter(Tasks)
|
++next;
|
||||||
);
|
Tasks.push_back(std::move(*itr));
|
||||||
|
m_ScheduledTasks.erase(itr);
|
||||||
|
itr = next;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// All the eligible tasks have been moved, bail out now
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute and delete each task:
|
// Execute and delete each task:
|
||||||
|
Loading…
Reference in New Issue
Block a user